开发者

Problem with DetailsView events

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="Link开发者_JAVA百科Button3" 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..


You have specify a CommandName for LinkButton so why you don't use it?

if(e.CommandName == "Select")
{
   //Do something
} 

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜