日期:2014-05-18  浏览次数:20514 次

在线等。。。各位大虾帮帮忙,如何取得当前选中的girdview的行数
想要一点击修改,将得到那一行的值 public void My_List_RowCommand(object sender, GridViewUpdateEventArgs e)
这个函数的参数不知道应该怎么写
 我的代码:
aspx:
<asp:GridView ID="My_List" runat="server" EmptyDataText="暂无记录" 
  AutoGenerateColumns="False" AllowSorting="True" Width="738px" OnRowCommand= "My_List_RowCommand " onselectedindexchanged="My_List_SelectedIndexChanged" >

<asp:TemplateField HeaderText="修改">
  <ItemTemplate>
  <asp:LinkButton ID="LB_alert" Text="修改" runat="server" OnClick="LB_alert_change"></asp:LinkButton>
  </ItemTemplate>
  </asp:TemplateField>


.cs:
public void My_List_RowCommand(object sender, GridViewUpdateEventArgs e)
  {
  string id = My_List.Rows[e.RowIndex].Cells[1].Controls[0].ToString().Trim();
  //string id = My_List.Rows[e.RowIndex].Cells[2].ToString().Trim();
  LB_ID.Text = id;
  }

------解决方案--------------------
<ItemTemplate>
<asp:LinkButton ID="LB_alert" Text="修改" runat="server" CommandArgument='<%# Eval("ID") %>' CommandName="Del" OnClick="LB_alert_change"></asp:LinkButton>
</ItemTemplate>

.cs:
public void My_List_RowCommand(object sender, GridViewUpdateEventArgs e)
{
if (e.CommandName == "Del")
{
 string id = e.CommandArgument.ToString();
}
}