By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,669 Members | 2,546 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,669 IT Pros & Developers. It's quick & easy.

DataGrid & CheckBox Column

P: n/a
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.
--
Be Cool!
Jul 21 '05 #1
Share this Question
Share on Google+
1 Reply


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

Thanks.

"thejackofall" wrote:
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.
--
Be Cool!

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.