请问一下,gridview有一模板列,模板列里有两个控件,分别是textbox和button.当点击button,怎么获取该行对应的textbox填入的值?
解决方案 »
- 将xml数据插入到数据表,或者将dataset数据插入到数据库表,下面是我的xml文件内容
- asp.net c# 中 用存储过程返回多个记录集 要怎么使用啊
- asp.net乱码问题
- VS2003的DATAGRID和EXCEL难题
- 一个很简单的Request问题,在线等谢谢!!
- 请教个问题!~!~
- 初学者关于Microsoft Visual Studio .NET 2003的问题?在线等待中...先谢了:)
- 网站根目录的路径写法怎么写?
- 我的VS崩溃了!卸不掉装不上!
- 调用水晶报表出错!急急急急急急!
- 求助(asp.net,vb):关于判断request.params("id")改变listbox的选定的错误
- 请假报销系统 要求自定义工作流???
在rowcreating 时 给 button 命名个cmdname
点击BUTTON时就触发了selectIndexChanging事件,
在事件中写
textbox txt=(.....此行(textbox)findControl["id "]).text;OK
在GridView1的RowDataBound事件中输入如下代码:
if(e.Row.RowType==DataControlRowType.DataRow)
((Button)e.Row.Cells[0].FindControl("Button1")).CommandArgument = e.Row.RowIndex.ToString();2.在模板列的Button1的Click事件中输入如下代码:
Button myB = (Button)sender;
TextBox myT = (TextBox)GridView1.Rows[Convert.ToInt32(myB.CommandArgument)].FindControl("TextBox1");
Response.Write(myT.Text);一切OK!
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TextBox txt = e.Row.FindControl("TextBox1") as TextBox;
Button button = e.Row.FindControl("Button1") as Button;
button.Attributes.Add("onclick","window.alert('"+txt.Text+"')");
}
}
{
Button btn = (Button)sender;
TableCell cell = btn.Parent as TableCell;
TextBox txt = cell.FindControl("TextBox1") as TextBox;
Response.Write(txt.Text);
}
这个做法也可以。具体做法如下: <asp:TemplateField HeaderText="Type">
<ItemTemplate>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<asp:Button ID="Button2" runat="server" Text="Query" CommandName="Select" />
</ItemTemplate>
</asp:TemplateField>
protected void GridView2_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
TextBox txt = (TextBox)this.GridView2.Rows[e.NewSelectedIndex].FindControl("TextBox4");
Response.Write(txt.Text);
}