vendredi 3 juin 2016

DataGrid one row of checkbox checked should change another row of checkbox visibility using asp.net

I've one DataGrid in my page(.aspx) and the code is given below,

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)
#
#
---------------------------------------

If i check 5th checkbox, needs to disable 4th checkbox in the datagrid. Can anyone please suggest how to do it?




Aucun commentaire:

Enregistrer un commentaire