日期:2014-05-17  浏览次数:20462 次

GridView怎么得到这一行的索引( //我想在这里得到鼠标当前在哪一行,是指在GridView第几行数据)
//这是我的前台代码
<asp:GridView ID="showNewsData" Width="100%" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#336666" GridLines="Horizontal" OnRowCommand="showNewsData_RowCommand" OnRowDataBound="showNewsData_RowDataBound">
  <Columns>
  <asp:BoundField DataField="NewsInformatioId" HeaderText="Id" />
  <asp:BoundField DataField="NewTypeName" HeaderText="新闻类型名称" />
  <asp:BoundField DataField="NewTime" HeaderText="发表日期" />
  <asp:BoundField DataField="NewAuthor" HeaderText="新闻作者" />
  <asp:BoundField DataField="NewsInformationName" HeaderText="新闻标题" />
  <asp:BoundField DataField="NewImgPath" HeaderText="新闻图片路径" />
  <asp:BoundField DataField="NewsInformationTxt" HeaderText="新闻内容" />
  <asp:TemplateField HeaderText="编辑">
  <ItemTemplate>
  <asp:ImageButton ID="imgbutAlterDate" CommandArgument='<%#Eval("NewsInformatioId") %>' CommandName="imgbutAlterDate" ImageUrl="~/NewsManage/edt.gif" runat="server" />
  </ItemTemplate>
  </asp:TemplateField>
  <asp:TemplateField HeaderText="删除">
  <ItemTemplate>
  <asp:ImageButton ID="imgbutDeleteData" CommandArgument='<%#Eval("NewsInformatioId") %>' CommandName="imgbutDeleteData" runat="server" ImageUrl="~/NewsManage/del.gif" />
  </ItemTemplate>
  </asp:TemplateField>
  </Columns>
  </asp:GridView>
//后台代码
 protected void showNewsData_RowCommand(object sender, GridViewCommandEventArgs e)
{
  if (e.CommandName == "imgbutAlterDate")//编辑数据  
  {
  //我想在这里得到鼠标当前在哪一行,是指在GridView第几行数据

  }
}

------解决方案--------------------
C# code
    protected void showNewsData_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "imgbutAlterDate")//编辑数据   
        {
            //我想在这里得到鼠标当前在哪一行,是指在GridView第几行数据
            Control control = e.CommandSource as Control;
            GridViewRow row = control.NamingContainer as GridViewRow;
            Response.Write(row.RowIndex);
        }
    }