Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting at values in gridview edit mode 1

Status
Not open for further replies.

mrp9090

Programmer
Joined
May 22, 2006
Messages
71
Location
GB
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();
}
 
Are you populating the GridView on the page load? If so, are you checking if the page is a PostBack?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
The problem with doing that is that I need to refresh the gridview every time a new date is selected in a gridview at the top of the page. Data binding on selectedindexchanged doesn't update the gridview, so I am using Page_Load to do this.
 
You'll have to check if the page is a postback and only bind it there if it isn't otherwise you'll get the problem you are having now. I don't understand what you mean about binding from another event though...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Sorry, just getting a little confused there. What I meant was that I was doing Gridview.DataBind() in a dropdown onselectedindexchanged event. I've now got it working...many thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top