当用户在GridView中单击行时,如何更新复选框状态? [英] How to update checkbox status when a user clicks on row in GridView?

查看:78
本文介绍了当用户在GridView中单击行时,如何更新复选框状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带CheckBox的GridView,我希望当用户点击复选框被选中的行时,以及当用户点击该行时,然后复选框被取消选中。



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: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.

推荐答案

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.
            }
       }


这篇关于当用户在GridView中单击行时,如何更新复选框状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆