如何从gridview向SQlDataSource传递参数?
Gridview 有许多列和一个删除按钮。删除按钮是一个控件,如 TemplateField
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnDelete" CommandName="Delete" Text='<%# Eval("disabled").ToString()=="False" ? "Disabled" : "Enabled" %>'
OnClientClick="return confirm('Are you sure you want to take this action?');"
runat="server"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
现在关联 SQLDataSource 的删除命令的存储过程需要两个参数。一个来自 DataKeyNames (RowID),另一个我想传递的是 btnDelete 的文本(True 或 False)。
我怎样才能实现它?
Gridview has many columns and a Delete button as well. Delete button is a control as TemplateField
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnDelete" CommandName="Delete" Text='<%# Eval("disabled").ToString()=="False" ? "Disabled" : "Enabled" %>'
OnClientClick="return confirm('Are you sure you want to take this action?');"
runat="server"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
Now associated SQLDataSource's Delete command's stored procedure is expecting two parameters. One is going from DataKeyNames (RowID), other one i wanna pass is the Text of btnDelete (True or False).
How can i achieve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议在后面的代码中执行此操作。单击 btnDelete 时,我将迭代 gridview 中的每一行并检查所有数据键名。一旦我找到您要删除的那个,您将需要将其发送回您的数据库。您可以使用 linq、ado.net 等 orm,也可以使用直接的 sqlcmd。
I would recommend doing it in the code behind. On btnDelete click i would iterate through every row in your gridview and check all the datakeynames. Once i found the one you want to delete you will need to send that back to you db. You can use either an orm like linq, ado.net, or a straight sqlcmd.
请参阅此代码。我实施并且工作正常
Please See this Code. I implement and works fine