DataGrid & CheckBox Column

G

Guest

Hi.

I have a checkbox column in my datagrid like this:

<Columns>
<asp:TemplateColumn HeaderText=" ">
<ItemTemplate>
<asp:CheckBox ID='Selection'
runat="server"></asp:CheckBox>
<asp:Label ID="SelectID" Visible="False" Text='<%#
DataBinder.Eval(Container.DataItem, "CustomerID") + "_" +
DataBinder.Eval(Container.DataItem, "OrderID") %>' Runat=server />
</ItemTemplate>
</asp:TemplateColumn>

When I try to get the state of checked checkboxes, it's telling me that it's
not checked. I tried EnableViewState=true, but the result is the same.

Here is my code behind:

private void btnInclude_Click(object sender, System.EventArgs e)
{
System.Web.UI.WebControls.CheckBox oCheckBox;
string sID;

foreach (DataGridItem oItem in DataGrid1.Items)
{
oCheckBox = (System.Web.UI.WebControls.CheckBox)
oItem.FindControl("Selection");
sID = CustomerType.SelectedValue + "_" + ((Label)
oItem.FindControl("SelectID")).Text;

if (oCheckBox.Checked)
{
sID = CustomerType.SelectedValue + "_" + ((Label)
oItem.FindControl("SelectID")).Text;
int nTemp = 0;
}
}

However, the value of sID comes out correctly. Your input is appreciated.
 
G

Guest

It turns out that the problem is in the Page_load because I am binding to a
datagrid.

Thanks.
 

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

Top