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

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]