首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

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

2012-02-05 
GidView模板列中文本框取值问题我的GV模板列中画了一个文本框,一个按钮.点击按钮是得到文本本框的值.若是

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]

热点排行