如何获得按钮单击行值 [英] How to get Row value on button Click

查看:180
本文介绍了如何获得按钮单击行值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"
  OnItemDataBound="Repeater1_ItemDatabound">
    <ItemTemplate>
      <tr>
        <td>
          <%#Eval("Priority") %>
        </td>
        <td>
        <%#Eval("ProjectName") %>
        </td>                 
        <td>
          <%#Eval("DisplayName") %>
        </td>
        <td>
          <asp:HyperLink ID="HyperLink1" runat="server"
            NavigateUrl='<%# Eval("EmailID" , "mailto:{0}") %>'
            Text='<%# Eval("EmailID") %>'></asp:HyperLink>
        </td>
        <td>
          <%#Eval("ProjectID") %>
        </td>
        <td>
          <asp:Button ID="btnCompleteProject" runat="server" Text="Close Project"
            OnCommand="CloseProject"  CommandName="Close"
            CommandArgument='<%# Eval("ProjectID") %>' />

我如何得到我在其中单击关闭按钮项目(btnCompleteProject)行的专案编号?

How do I get the ProjectID of the Row in which I click the close Project Button(btnCompleteProject) ?

推荐答案

您可以添加一个<一个href=\"http://www.google.com.br/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CFsQFjAA&url=http://msdn.microsoft.com/pt-br/library/system.web.ui.webcontrols.repeater.itemcommand.aspx&ei=K_7yT9ipIYjH0QHdwuHyCQ&usg=AFQjCNFLG3qIXZc5ywLySaCQFlAIENHxfw&sig2=z795QAVFg7-pGTT7BjKwhg\"相对=nofollow> ItemCommand事件到Repeater控件并添加一个科尔是这样的:

You can add an ItemCommand event to the repeater control and add a cole something like this:

public void Repeater1_ItemCommand(Object Sender, RepeaterCommandEventArgs e) 
{
    // check if the command name is close (if it's the button)
    if (e.CommandName == "Close") {
       // get CommandArgument you have seeted on the button
       int projectd = (int)e.CommandArgument;

       // your code here...

    }
}  

和加中继器标签,你的事件:

And add the repeater tag, you event:

<asp:Repeater ID="Repeater1" 
   runat="server" 
   DataSourceID="SqlDataSource1" 
   OnItemDataBound="Repeater1_ItemDatabound" 
   OnItemCommand="Repeater1_ItemCommand">
...
</asp:Repeater>

这篇关于如何获得按钮单击行值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆