当前位置: 代码迷 >> ASP.NET >> GidView模板列中文本框取值有关问题
  详细解决方案

GidView模板列中文本框取值有关问题

热度:6617   发布时间:2013-02-25 00:00:00.0
GidView模板列中文本框取值问题
我的GV模板列中画了一个文本框,一个按钮.
点击按钮是得到文本本框的值.
若是能得到当前点击按钮的行号,也算是完了功能.
请各位给看下哈.!

------解决方案--------------------------------------------------------
HTML code
<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]
  相关解决方案