Click here to Skip to main content
15,920,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a GridView with CheckBox and I would like to do when a user clicks on the row that the checkbox gets checked, and when the user clicks back on the row, then checkbox gets unchecked.

ASP.NET
<asp:GridView ID="GridView1" runat="server" GridLines="None" AutoGenerateColumns="false"
OnPreRender="gridview_PreRender" AllowPaging="false" EmptyDataText="No Records Found"
EmptyDataRowStyle-ForeColor="Red" Width="100%" OnSelectedIndexChanging="GridView1_SelectedIndexChanging"
OnRowDataBound="GridView1_RowDataBound" ShowFooter="false" >
	<Columns>
		<asp:BoundField DataField="ModuleID" HeaderText="Module ID" Visible="false" HeaderStyle-Font-Bold="true" />
		<asp:BoundField DataField="ModuleName" HeaderText="Module Name" HeaderStyle-Font-Bold="true" />
		<asp:TemplateField ItemStyle-HorizontalAlign="Center">
			<HeaderTemplate>
				<input id="chkAll"  önclick="javascript:SelectAllCheckboxes(this);"  runat="server"
					type="checkbox" />
			</HeaderTemplate>
			<ItemTemplate>
				<asp:CheckBox runat="server" ID="CheckBoxField"  Checked='<%#DataBinder.Eval(Container.DataItem, "ActiveStatus")%>' />
			</ItemTemplate>
		</asp:TemplateField>
		<asp:BoundField DataField="SubModuleID" HeaderText="Sub Module ID" Visible="false"
			HeaderStyle-Font-Bold="true" />
		<asp:BoundField DataField="SubModuleName" HeaderText="Sub Module Name" HeaderStyle-Font-Bold="true" />
	</Columns>
	<HeaderStyle CssClass="GridviewScrollHeader" />
	<RowStyle CssClass="GridviewScrollItem" />
	<AlternatingRowStyle CssClass="gridview_alter" />
</asp:GridView>


I already google it, but i didn't get good example. If user clicks on cell which is under "Sub Module Name" field then i must update respective check box status either checked or unchecked.
Posted

1 solution

C#
Please write code like in CellClick event of Datagridview.

private void dgvSchemeMaster_CellClick(object sender, DataGridViewCellEventArgs e)
       {
           if (e.RowIndex > -1)
           {
               //Here Check Checkstate property
               bool flag = dgvSchemeMaster.Rows[e.RowIndex].Cells[x].Value //x your column index
               //please do type casting yourself.
            }
       }
 
Share this answer
 
Comments
mn.sathish 26-Nov-13 5:34am    
It seems you have posted for Win App Solution. I need ASP .Net

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