Click here to Skip to main content
15,891,925 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to show the record in grid view,and i have the field call status, when user will check the check box status will be show ACTIVE and When user will uncheked the box then status will be show Inactive?
Posted

Add Template Field in yopur grid view under columns tag.

XML
<asp:TemplateField HeaderText="Active/Inactive">
                           <EditItemTemplate>
                               <asp:CheckBox ID="CheckBox1" runat="server" />
                           </EditItemTemplate>
                           <ItemTemplate>
                               <asp:CheckBox ID="CheckBox1" runat="server" />
                           </ItemTemplate>
                       </asp:TemplateField>


//------- code for check box click
C#
for (int i = 0; i < int.Parse(RegView.Rows.Count.ToString()); i++)
{
CheckBox myCheckBox = (CheckBox)RegView.Rows[i].FindControl("CheckBox1");
                    if (myCheckBox.Checked == true)
                    {
                      // do the activity
                    }
}
 
Share this answer
 
Comments
AshishChaudha 12-Apr-12 7:39am    
Is active/inactive status takes place at the same time when user check or uncheck the checkbox ???
ravi24june 12-Apr-12 7:50am    
Yes. If rows[i].checked== true then set the status =Active otherwise set the status = inactive.

You have to run a loop for entire row of gridview to know which checkbox(of row) is true or false.
 
Share this answer
 
XML
<asp:GridView ID="GridView1" runat="server" BorderStyle="Double"
            ForeColor="#CC0000" CssClass= "grid" >

            <Columns>
<asp:TemplateField >
<HeaderTemplate>
    <asp:CheckBox ID="CheckBox1" Text = "select All" AutoPostBack="true"
    oncheckedchanged="CheckBox1_CheckedChanged"
     runat="server" />
</HeaderTemplate>
<ItemTemplate>

<asp:CheckBox ID="Check_select" Text = "select" runat="server"/>
</ItemTemplate>

<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
</Columns>
        </asp:GridView>
 
Share this answer
 
XML
<asp:TemplateField HeaderText="Active/Inactive">
                           <ItemTemplate>
                               <asp:label id="lblStatus" runat="server" xmlns:asp="#unknown" />
                               <asp:CheckBox ID="CheckBox1" runat="server" />
                           </ItemTemplate>
                       </asp:TemplateField>




C#
for (int i = 0; i < int.Parse(RegView.Rows.Count.ToString()); i++)
{
CheckBox myCheckBox = (CheckBox)RegView.Rows[i].FindControl("CheckBox1");
Label lblStat=(Label)RegView.Rows[i].FindControl("lblStatus");

                    if (myCheckBox.Checked == true)
                    {
                          lblStat.Text="Active" 
                    }
                    else
                    {
                          lblStat.Text="InActive"; 
                    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900