DataGrid选中的一行复选框应该使用asp.net更改另一行复选框可见性

时间:2016-06-03 14:58:27

标签: c# asp.net checkbox datagrid

我的页面中有一个DataGrid(.aspx),代码如下:

Page.aspx

<asp:DataGrid ID="myDataGrid" runat="server" AutoGeneratedColumns="false" AllowPaging="true" AllowSorting="true" PageSize="5" OnPageIndexChanged="myDataGrid_Page"  OnItemDataBound="myDataGrid_ItemDataBound">

<Columns>
<asp:TemplateColumn HeaderText="SlNo" Visible="False">
<ItemTemplate>
      <asp:Label ID="_lblID" Text='<% DataBinder.Eval(Container.DataItem, "id")%>' runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Select">
<ItemTemplate>
      <asp:CheckBox ID="_chkSelect" runat="server"/> </ItemTemplate> </asp:TemplateColumn>
.... 
</Columns>
</asp:DataGrid>

Page.aspx.cs

protected void myDataGrid_Page(object source, DataGridPageChangedEventArgs e)
{
   myDataGrid.CurrentPageIndex = e.NewPageIndex;
   _BindDataGrid();
}

protected void myDataGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
   if(e.Item.ItemType != ListItemType.Header && e.Item.ItemType !=     ListItemType.Footer)
  {
   Label lbl = e.Item.FindControl("_lblID") as Label;
   CheckBox chk = e.Item.FindControl("_chkSelect") as CheckBox;
   chk.Checked = lbl.Text.ToLower() == "2";
  }
}

UI

---------------------------------------
Select
---------------------------------------
#
#
#(checked)
#
#
---------------------------------------

如果我选中第5个复选框,则需要禁用数据网格中的第4个复选框 如果我取消选中5th复选框,则需要在datagrid中启用第4个复选框。 任何人都可以建议怎么做?

0 个答案:

没有答案