如何通过单击按钮获取网格视图内的下拉列表的值?
我在网格视图中有一个下拉列表。现在我希望当我单击按钮时我可以检查下拉列表的值。我已经为其触发了 gridview 的 rowcommand 事件,但调试器无法到达那里..请帮助我..我的代码是
Protected Sub grd_Test_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grd_Test.RowCommand
If e.CommandName = "Select" Then
End If
End Sub
我的源代码是
<asp:GridView ID="grd_UnAssignProperties" runat="server" AutoGenerateColumns="False"><Columns>
<asp:TemplateField HeaderText="Assign To">
<ItemTemplate>
<asp:DropDownList ID="drp_UnAssignProp" runat="server">
<asp:ListItem Value="" >Default</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns></asp:GridView><tr><td><asp:Button ID="btn_Save" runat="server" CommandName="Select" Text="Submit" />
I have a dropdownlist inside the gridview. Now i want when i click on a button then i can check the value of dropdownlist. I have fired rowcommand event of gridview for it but debugger is not able to go reach there..Please help me..My Code is
Protected Sub grd_Test_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grd_Test.RowCommand
If e.CommandName = "Select" Then
End If
End Sub
my Source code is
<asp:GridView ID="grd_UnAssignProperties" runat="server" AutoGenerateColumns="False"><Columns>
<asp:TemplateField HeaderText="Assign To">
<ItemTemplate>
<asp:DropDownList ID="drp_UnAssignProp" runat="server">
<asp:ListItem Value="" >Default</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns></asp:GridView><tr><td><asp:Button ID="btn_Save" runat="server" CommandName="Select" Text="Submit" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个
try this
尝试
try
首先,由于按钮
btn_Save
不在GridView
内部,因此单击它不会引发grd_Test_RowCommand
,要么移动按钮在 GridView 内,或者您必须像这样手动引发它:从 asp.net 论坛复制:
现在关于您原来的问题,这就是您如何获取
DropDownList
的选定值里面RowCommand
事件:编辑:修复代码以获取引发 RowCommand 事件的当前行
First of all, since the button
btn_Save
isn't inside theGridView
, clicking on it won't raise thegrd_Test_RowCommand
, either move the button insideGridView
or you have to raise it manually like this:Copied from asp.net forum:
Now regarding your original question, this is how you can get the selected value of
DropDownList
insideRowCommand
event:Edit: Fixed code to get the current row, for which the RowCommand event was raised