getting at edited values in gridview

M

Mike P

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_RowUpdating(object sender,
GridViewUpdateEventArgs 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.DataItemIndex].Value;

//get all other fields to be updated
DropDownList ddl1 = new DropDownList();
ddl1 =
(DropDownList)GridView1.Rows[index].FindControl("ddlCompanyName");
long lngCompanyKey = Convert.ToInt64(ddl1.SelectedValue);

DropDownList ddl2 = new DropDownList();
ddl2 =
(DropDownList)GridView1.Rows[index].FindControl("ddlForecastType");
char chrForecastType = Convert.ToChar(ddl2.SelectedValue);

TextBox txt1 = new TextBox();
txt1 =
(TextBox)GridView1.Rows[index].FindControl("txtMoneyValue");
double dblMoneyValue = Convert.ToDouble(txt1.Text);

DropDownList ddl3 = new DropDownList();
ddl3 =
(DropDownList)GridView1.Rows[index].FindControl("ddlForecastPercentage")
;
double dblForecastPercentage =
Convert.ToDouble(ddl3.SelectedValue);

TextBox txt2 = new TextBox();
txt2 = (TextBox)GridView1.Rows[index].FindControl("txtDueDate");
DateTime dtmDueDate = Convert.ToDateTime(txt2.Text);

//create update parameters
SqlDataSource1.UpdateParameters.Clear();

SqlDataSource1.UpdateParameters.Add("ForecastKey",
TypeCode.Int32, intID.ToString());
SqlDataSource1.UpdateParameters.Add("UserKey", TypeCode.Int32,
UserKey.ToString());
SqlDataSource1.UpdateParameters.Add("CompanyKey",
TypeCode.Int64, lngCompanyKey.ToString());
SqlDataSource1.UpdateParameters.Add("ForecastType",
TypeCode.Char, chrForecastType.ToString());
SqlDataSource1.UpdateParameters.Add("MoneyValue",
TypeCode.Double, dblMoneyValue.ToString());
SqlDataSource1.UpdateParameters.Add("ForecastPercentage",
TypeCode.Double, dblForecastPercentage.ToString());
SqlDataSource1.UpdateParameters.Add("DueDate",
TypeCode.DateTime, dtmDueDate.ToString());


//update forecast table
DataAccess da = new DataAccess();

da.UpdateForecast(intID, UserKey,
lngCompanyKey, chrForecastType,
dblMoneyValue, dblForecastPercentage,
dtmDueDate);

GridView1.EditIndex = -1;

//refresh gridview
GridView1.DataBind();
}
 
K

K B

For example, I want to get the value of the vlaue in the UserName field
in EditItemTemplate. On the RowUpdating event, I use this:

Dim sUserName As String = e.NewValues("UserName")

HTH,
KB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top