How do you get access to the values you have entered under edit mode in
a gridview? I only seem to be able to access the values prior to them
being edited.
protected void GridView1_RowUp dating(object sender,
GridViewUpdateE ventArgs e)
{
// 1)Convert the row index stored in the CommandArgument
property to an Integer
int index = e.RowIndex;
// Retrieve the row that contains the button clicked by the user
from the Rows collection
GridViewRow row = GridView1.Rows[index];
//get datakeys (forecastkey)
int intID = (int)GridView1. DataKeys[row.DataItemInd ex].Value;
//get all other fields to be updated
DropDownList ddl1 = new DropDownList();
ddl1 =
(DropDownList)G ridView1.Rows[index].FindControl("d dlCompanyName") ;
long lngCompanyKey = Convert.ToInt64 (ddl1.SelectedV alue);
DropDownList ddl2 = new DropDownList();
ddl2 =
(DropDownList)G ridView1.Rows[index].FindControl("d dlForecastType" );
char chrForecastType = Convert.ToChar( ddl2.SelectedVa lue);
TextBox txt1 = new TextBox();
txt1 =
(TextBox)GridVi ew1.Rows[index].FindControl("t xtMoneyValue");
double dblMoneyValue = Convert.ToDoubl e(txt1.Text);
DropDownList ddl3 = new DropDownList();
ddl3 =
(DropDownList)G ridView1.Rows[index].FindControl("d dlForecastPerce ntage")
;
double dblForecastPerc entage =
Convert.ToDoubl e(ddl3.Selected Value);
TextBox txt2 = new TextBox();
txt2 = (TextBox)GridVi ew1.Rows[index].FindControl("t xtDueDate");
DateTime dtmDueDate = Convert.ToDateT ime(txt2.Text);
//create update parameters
SqlDataSource1. UpdateParameter s.Clear();
SqlDataSource1. UpdateParameter s.Add("Forecast Key",
TypeCode.Int32, intID.ToString( ));
SqlDataSource1. UpdateParameter s.Add("UserKey" , TypeCode.Int32,
UserKey.ToStrin g());
SqlDataSource1. UpdateParameter s.Add("CompanyK ey",
TypeCode.Int64, lngCompanyKey.T oString());
SqlDataSource1. UpdateParameter s.Add("Forecast Type",
TypeCode.Char, chrForecastType .ToString());
SqlDataSource1. UpdateParameter s.Add("MoneyVal ue",
TypeCode.Double , dblMoneyValue.T oString());
SqlDataSource1. UpdateParameter s.Add("Forecast Percentage",
TypeCode.Double , dblForecastPerc entage.ToString ());
SqlDataSource1. UpdateParameter s.Add("DueDate" ,
TypeCode.DateTi me, dtmDueDate.ToSt ring());
//update forecast table
DataAccess da = new DataAccess();
da.UpdateForeca st(intID, UserKey,
lngCompanyKey, chrForecastType ,
dblMoneyValue, dblForecastPerc entage,
dtmDueDate);
GridView1.EditI ndex = -1;
//refresh gridview
GridView1.DataB ind();
}
*** Sent via Developersdex http://www.developersdex.com ***