views:

312

answers:

1

I like to update just the value of my checkbox in a asp grid.

so i thought i bind the id to the checkbox ( but how?) and fire an update in code behind by clicking the checkbox.

but how can I get the ID, and where I have to bind this id to get it in code behind in the event?

Thanks

A: 

Here is what I've managed to do. (Be aware there should be an easier way to do this. I'm very new to ASP.NET)

Here you have a TemplateField in a GridView. Inside it there is an UpdatePanel and the CheckBox is inside it. This is done to make the checking of the TextBox do post in the backgroung (ajax). You might not need it (UpdatePanel) at all.

<asp:TemplateField HeaderText="Private" SortExpression="IsPrivate">
  <ItemTemplate>
    <asp:UpdatePanel ID="upIsPrivate" runat="server" UpdateMode="Always" ChildrenAsTriggers="true">
      <ContentTemplate>
        <asp:CheckBox ID="chkIsPrivate" runat="server" OnCheckedChanged="chkIsPrivate_CheckedChanged" AutoPostBack="true" />
      </ContentTemplate>
    </asp:UpdatePanel>
  </ItemTemplate>
</asp:TemplateField>

And this is the method that handles this. Notice that I get the Id from the GridViewRow that contains the CheckBox:

GridViewRow row = (GridViewRow)((CheckBox)sender).Parent.Parent.Parent.Parent;

protected void chkIsPrivate_CheckedChanged(object sender, EventArgs e)
{
  if (editMode)
  {
    GridViewRow row = (GridViewRow)((CheckBox)sender).Parent.Parent.Parent.Parent;
    Int32 id = (Int32)uxPhoneCallList.DataKeys[row.RowIndex]["Id"];
    CheckBox isPrivate = (CheckBox)row.FindControl("chkIsPrivate");

    PhoneCall phoneCall = PhoneCallManager.GetById(id);
    ...
  }
}
Bojan Milenkoski