无法获取gridview中的复选框的值 [英] Can't Get the value of Checkbox inside gridview
问题描述
我在获取gridview内复选框的值时遇到问题.我的网格视图代码是:
< asp:GridView ID =" ="span> runat =" 服务器" < RowStyle =" 白色" ForeColor 黑色" 包装 =" True" / < 列 >
< asp:TemplateField HeaderText =" < HeaderStyle =" Center" VerticalAlign 中间" 宽度 =" 50像素" / < ItemStyle =" Center" VerticalAlign 中间" 宽度 =" 50像素" / < HeaderTemplate >
< asp:CheckBox ID =" onclick javascript :HeaderClick(this);" 运行 =" / < /HeaderTemplate >
< ItemTemplate >
< asp:CheckBox ID =" runat 服务器" AutoPostBack 错误" / < /ItemTemplate >
< /asp:TemplateField >
< asp:TemplateField HeaderText =" ItemStyle-HorizontalAlign HeaderStyle-Font-Underline =" >
< ItemTemplate >
< asp:LinkButton ID =" runat 服务器" 文本 <% #Eval(" )%>'
CommandArgument =' " Employee_User_Id")%> ' OnCommand =" User_Id_OnClick" < /asp:LinkButton >
< /ItemTemplate >
< /asp:TemplateField >
< /列 >
< /asp:gridview >
注意::我在我中称呼"
报价:
onclick =" javascript:HeaderClick(this);
"全选的Gridview
上面的代码按我想要的方式工作.问题我从后面的代码中得到复选框的值.选中复选框后,我单击提交按钮.在BUTTON单击事件后面的代码中,我想获取所有选中的复选框的值
我的代码背后的代码是
对于 i As 整数 = 0 到 empinfomation.Rows.Count- 1
Dim chkDelete As CheckBox = _ DirectCast ( empinfomation.Rows( 0 ).Cells( 0 ).FindControl( 0 >" chkBxSelect"),复选框)
如果 chkDelete 是不是 什么都没有 然后
如果 chkDelete.选中然后
' 在此处进行操作
结束 如果
结束 如果
下一步
如果您注意到我正在传递
在我的gridview中.我想为每个选中的复选框获取此值.报价:CommandArgument =''<%#Eval("Employee_User_Id")%>''
谢谢
按如下所示更改代码
将chk删除为复选框= _ DirectCast(empinfomation.Rows(i).FindControl(" ),CheckBox)
大家好,感谢您的回复.那是我的臭虫. btn click事件,我正在更新gridview数据,默认情况下,我的复选框值为false.这就是我变得虚假的原因.
I am having problem getting the value of check box inside gridview. my grid view code is :
<asp:GridView ID="empinfomation" runat="server">
<RowStyle BackColor="white" ForeColor="black" Wrap="True" />
<Columns>
<asp:TemplateField HeaderText="Select">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
<HeaderTemplate>
<asp:CheckBox ID="chkBxHeader" onclick="javascript:HeaderClick(this);" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkBxSelect" runat="server" AutoPostBack="False" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Employee Name" ItemStyle-HorizontalAlign="left" HeaderStyle-Font-Underline="true">
<ItemTemplate>
<asp:LinkButton ID="Employee_Name" runat="server" Text='<%#Eval("Employee_Name") %>'
CommandArgument='<%#Eval("Employee_User_Id") %>' OnCommand="User_Id_OnClick">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</columns>
</asp:gridview>
NOTE:: i am calling "
Quote:onclick="javascript:HeaderClick(this);
"" In my gridview for select all
The Above code work as i wanted to work. Problem i am having getting the value of check box from code behind . After i Selected check Box /Boxes , i Click SUBMIT BUTTON . In code behind on BUTTON click event i want to get the value for all checked checkbox
My Code behind Code is
For i As Integer = 0 To empinfomation.Rows.Count - 1
Dim chkDelete As CheckBox = _ DirectCast(empinfomation.Rows(0).Cells(0).FindControl("chkBxSelect"), CheckBox)
If chkDelete IsNot Nothing Then
If chkDelete.Checked Then
'Do stuff here
End If
End If
Next
IF you note i am passing
Quote:CommandArgument=''<%#Eval("Employee_User_Id") %>''
in my gridview . i want to get this value for each checked check box.
Thanks
Change your code as below
Dim chkDelete As CheckBox = _ DirectCast(empinfomation.Rows(i).FindControl("chkBxSelect"), CheckBox)
Hey guys thanks for your responses . It was my codding bug . btn click event i was updating my gridview data and by default my check box value is false . This is the reason i was getting false.
这篇关于无法获取gridview中的复选框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!