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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing checkbox value from datagrid

Status
Not open for further replies.

j9

Programmer
Jun 6, 2001
90
US
Hi, I'm new to .net and I'm trying to figure out how to access the value of a checkbox within a datagrid. The datasource for the datagrid is an arraylist of groupmember objects. The code below produces a value of 'true' for variable isReviewer even if the checkbox is unchecked.

Here's what I have:

IN HTML:----------------------------
<asp:DataGrid id="dgGroupMembers" style="Z-INDEX: 127; LEFT: 48px; POSITION: absolute; TOP: 320px" runat="server" AutoGenerateColumns="False" AllowSorting="True" AllowPaging="True" Font-Size="Smaller" OnItemCommand="dgGroupMembers_Command">
<Columns>
<asp:BoundColumn DataField="FullName" ReadOnly="True" HeaderText="Name"></asp:BoundColumn>

<asp:TemplateColumn ItemStyle-HorizontalAlign="Center">
<HeaderTemplate>
Reviewer
</HeaderTemplate>
<ItemTemplate>
<asp:Checkbox Checked='<%# DataBinder.Eval(Container.DataItem, "IsReviewer") %>' runat="server" ID="chkIsReviewer" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn Text="update" CommandName="Update"></asp:ButtonColumn>
</Columns>
</asp:DataGrid>------------------------------------

IN grpmembers.aspx.cs:-------------------------------------
public void dgGroupMembers_Command(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
bool isReviewer;
CheckBox chkReviewer = (CheckBox) e.Item.Cells[1].Controls[1];
string strKey = dgGroupMembers.DataKeys[e.Item.ItemIndex].ToString();

bool isReviewer = chkReviewer.Checked;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top