GridView Databinding

H

Harlan.Vossos

I am using the GridView component to display data as an HTML table. I
create a dataset and manually bind the dataset to the grid as shown
below. One of the columns is displayed as a checkbox. I have button
outside the grid. When the button is clicked I want to iterate thru
the rows in the grid and update the database. The problem is when i
iterate the rows in the click event there are NO rows in the grid. The

DataGrid in version 1.1 would rebuild the grid from viewstate on
postbacks. Does the GridView do the same? or do you have to do
something special? I am aware of the sql data source and binding the
grid to it with no code, but i do not want to do this.


Protected void Page_Load(object sender, EventArgs e) {
if ( ! IsPostBack){
DataSet Data = GetDataset();
MyGridView.DataSource = Data
MyGridView.DataBind();
}
}


protected void DoClick(object sender, EventArgs e){


// I Get No Rows??? Why didn't the grids get re-binding from
viewstate????
foreach(GridViewRow Row in MyGridView.Rows) {
NotificationIds[Row.DataItemIndex] =
Convert.ToInt32 (MyGridView.DataKeys[Row.DataItemIndex].Value);
}
}
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top