DetailsView 事件的问题
我有一个带有按钮链接的列表,当单击按钮列表时会触发此事件:
protected void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e)
{
DetailsView dv = (DetailsView)sender;
LinkButton linkbtn = (LinkButton)dv.FindControl("LinkButton3");
string threadID = e.CommandArgument.ToString();
string threadName = linkbtn.Text;
Server.Transfer("~/AnswerQuestion.aspx?x=" + threadID+"&question=" + threadName + "&time=" + DateTime.Now);
}
LinkButton 的标记。
<ItemTemplate >
<asp:LinkButton ID="LinkButton3" runat="server" Text=<%# Eval("ThreadTitle") %> CommandName="Select" CommandArgument=<%# Eval("ThreadsID") %>>LinkButton</asp:LinkButton>
</ItemTemplate>
问题是我也允许分页..所以当单击某个页面时会触发Detailsview1_ItemCommand(例如,如果我们在第1页上,单击第2页,则触发该事件)..
我想通过包装来防止这种情况Server.Transfer 语句并设置一个条件,说明单击的是否是 buttonLink 而不是寻呼机... (我无法投射发件人..因为我得到了详细信息视图)
有可能吗..
I have a list with button links when a button list is clicked this event is triggered:
protected void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e)
{
DetailsView dv = (DetailsView)sender;
LinkButton linkbtn = (LinkButton)dv.FindControl("LinkButton3");
string threadID = e.CommandArgument.ToString();
string threadName = linkbtn.Text;
Server.Transfer("~/AnswerQuestion.aspx?x=" + threadID+"&question=" + threadName + "&time=" + DateTime.Now);
}
Mark up of the LinkButton.
<ItemTemplate >
<asp:LinkButton ID="LinkButton3" runat="server" Text=<%# Eval("ThreadTitle") %> CommandName="Select" CommandArgument=<%# Eval("ThreadsID") %>>LinkButton</asp:LinkButton>
</ItemTemplate>
The problem is that I allowed paging too..so the Detailsview1_ItemCommand is triggered when a certain page is clicked (e.g. if we are on page 1 and page 2 clicked, then the event is triggered)..
I want to prevent this by wrapping the Server.Transfer statement and make a condition that states whether it was the buttonLink that was clicked and not the pager...
(I cant cast sender..cause I get the DetailsView)
Is it possible..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已经为 LinkButton 指定了 CommandName 那么为什么不使用它呢?
顺便说一句,如果这个 LinkButton 除了转移到另一个页面之外不执行任何服务器操作,那么在这里使用简单的锚标记可能会更好。
You have specify a CommandName for LinkButton so why you don't use it?
By the way if this LinkButton doesn't perform any server action except transferring onto another page maybe would be better to use simple anchor tag here.