i have a aspx page where a gridview is placed ( list.aspx ) , in the code behind i am passing the gridview to a helper function ( in Helper.cs ) where the gridview has to be populated. i am building the gridview rows at runtime like below.
/* template to insert the check box in the gridview
public class CheckTemplate : ITemplate
{
public void InstantiateIn(System.Web.UI.Control container)
{
CheckBox ch = new CheckBox();
ch.ID = "chkUser";
ch.AutoPostBack = true;
container.Controls.Add (ch);
}
}
DataTable hTable;
DataRow hRow;
BoundField hDataField;
hTemplateField = new TemplateField();
hTemplateField.HeaderText = "Select";
hTemplateField.ItemTemplate = new CheckTemplate();
hResults.Columns.Add(hTemplateField);
hDataField = new BoundField();
hDataField.HeaderText = "First Name";
hDataField.ItemStyle.Wrap = false;
hDataField.DataField = "FirstName";
hResults.Columns.Add(hDataField);
hDataField = new BoundField();
hDataField.HeaderText = "Last Name";
hDataField.DataField = "LastName";
hDataField.ItemStyle.Wrap = false;
hResults.Columns.Add(hDataField);
Here i am running a stored procedure and for each row i am getting the values and populating the gridview like below.
hDataSet = cmd.ExecuteQuery("...");
hRow = hTable.NewRow();
hRow[0] = hDataSet.GetFieldValueByName("FirstName");
hRow[1] = hDataSet.GetFieldValueByName("LastName");
hTable.Rows.Add(hRow);
hView = new DataView(hTable);
hResults.DataSource = hView;
hResults.DataBind();
i wanted to know how to handle the checkchanged event for this as the grid is being populated in a different helper function :shock:
/* template to insert the check box in the gridview
public class CheckTemplate : ITemplate
{
public void InstantiateIn(System.Web.UI.Control container)
{
CheckBox ch = new CheckBox();
ch.ID = "chkUser";
ch.AutoPostBack = true;
container.Controls.Add (ch);
}
}
DataTable hTable;
DataRow hRow;
BoundField hDataField;
hTemplateField = new TemplateField();
hTemplateField.HeaderText = "Select";
hTemplateField.ItemTemplate = new CheckTemplate();
hResults.Columns.Add(hTemplateField);
hDataField = new BoundField();
hDataField.HeaderText = "First Name";
hDataField.ItemStyle.Wrap = false;
hDataField.DataField = "FirstName";
hResults.Columns.Add(hDataField);
hDataField = new BoundField();
hDataField.HeaderText = "Last Name";
hDataField.DataField = "LastName";
hDataField.ItemStyle.Wrap = false;
hResults.Columns.Add(hDataField);
Here i am running a stored procedure and for each row i am getting the values and populating the gridview like below.
hDataSet = cmd.ExecuteQuery("...");
hRow = hTable.NewRow();
hRow[0] = hDataSet.GetFieldValueByName("FirstName");
hRow[1] = hDataSet.GetFieldValueByName("LastName");
hTable.Rows.Add(hRow);
hView = new DataView(hTable);
hResults.DataSource = hView;
hResults.DataBind();
i wanted to know how to handle the checkchanged event for this as the grid is being populated in a different helper function :shock:
Last edited: