日期:2014-05-18 浏览次数:20597 次
<asp:GridView ID="base_gvMain" runat="server" Width="100%" OnRowCommand="base_gvMain_RowCommand"> <asp:TemplateField HeaderText="查看PLC现象"> <ItemTemplate> <asp:Button ID="btnPLC" Text="查看PLC现象" CssClass="btn_long" CommandName="PLC" CommandArgument="<%# ((GridViewRow)Container).RowIndex %>" runat="server" /> <asp:TextBox ID="txtValue" runat="server"/> </ItemTemplate> </asp:TemplateField>
------解决方案--------------------
<asp:Button ID="CheckButton" runat="server" Text="查看" CommandArgument= <%# Container.DisplayIndex%>
OnCommand="CheckButton_Click"/>
protected void CheckButton_Click(object sender, CommandEventArgs e)
{
string studentcode = e.CommandArgument.ToString();
}
------解决方案--------------------
code=C#]
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "MyCommand")
{
Button button = (Button)e.CommandSource;
GridViewRow row = (GridViewRow)button.Parent.Parent;
string a = row.Cells[1].Text.ToString();//获得第一个单元格的值
string b = this.GridView1.DataKeys[row.DataItemIndex].Values[0];//获得DataKeys的值
}
}
[/code]