Skip to content

Gridview with CheckBox

Aamir Khan

Asked Jun 20, 2012, 4:47 AM EDT2 answers
Share
LinkedInX
Hi friends,
 i have a gridview in that there is a Column for Check box and others are for Entering data like MaterialDescription,Quantity,etc.,
i have query for how to get Checkbox in gridview & on selecting a particular check box in that row the Quanity textbox in Gridview should be enabled or Disabled on unselect.

pls reply how can it be done!!!

regards,
aamir

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    You have to use itemtemplate to place the checkbox as mentioned below.

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
      AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="PersonID"
      DataSourceID="mySource" Width="366px" CellPadding="4"
      ForeColor="#333333" GridLines="None">
    <Columns>
      <asp:CommandField ShowSelectButton="True" />
      <asp:BoundField DataField="PersonID" HeaderText="PersonID"
      InsertVisible="False" ReadOnly="True" SortExpression="PersonID" />
      <asp:BoundField DataField="Name" HeaderText="Name"
      SortExpression="Name" />
      <asp:TemplateField HeaderText="Select">
      <ItemTemplate>
      <asp:CheckBox ID="chkSelect" runat="server" />
      </ItemTemplate>
      <HeaderTemplate>
      </HeaderTemplate>
      </asp:TemplateField>

    </Columns>

    <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
    <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
    <PagerStyle BackColor="#FFCC66" ForeColor="#333333"
      HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
    <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
    <AlternatingRowStyle BackColor="White" />
    </asp:GridView>

    Later you can attach a javascript event to enable and disable the particular row.

    http://bitswork09.wordpress.com/2012/03/20/enable-and-disable-controls-in-gridview-with-javascript/

    http://stackoverflow.com/questions/10491041/how-to-set-gridview-checkbox-to-checked-when-i-click-an-aspbutton-in-the-same-r

    http://challlengebrains.blogspot.in/2011/08/gridview-with-checkbox-select-all-and.html

    You can write server side event also to do  enable and disable the particular row.
    0
  • 0
    any other suggestion will be helpful
    0