0
<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") %>' />

如何获取单击关闭 Project Button(btnCompleteProject) 所在行的 ProjectID?

4

3 回答 3

2

您可以将ItemCommand 事件添加到转发器控件并添加类似这样的 cole:

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...

    }
}  

并添加转发器标签,您的事件:

<asp:Repeater ID="Repeater1" 
   runat="server" 
   DataSourceID="SqlDataSource1" 
   OnItemDataBound="Repeater1_ItemDatabound" 
   OnItemCommand="Repeater1_ItemCommand">
...
</asp:Repeater>
于 2012-07-03T14:16:38.150 回答
0

添加OnClick="btnCompleteProject_Click"到按钮标记,并添加一个处理程序:

protected void btnCompleteProject_Click(object sender, EventArgs e)
{
    var argValue = (int)((Button)sender).CommandArgument;
}

您还可以收听Repeater.ItemCommand,它也应该捕捉到按钮的点击。

于 2012-07-03T14:14:57.567 回答
0

Brian Mains 的回答是正确的,在标记中,您在按钮命令参数中设置 ProjectID 列的值。所以在按钮中点击这段代码

protected void btnCompleteProject_Click(object sender, EventArgs e)
 {
   var argValue = (int)((Button)sender).CommandArgument;
 }

您将获得 ProjectID

于 2012-07-03T15:00:01.397 回答