如何获取gridview中模板列中控件的值 我的页面上有个gridview,该gridview中有一个模板列,该模板列中放置了一个textbox控件,在页面上还有个button按钮,当我单击按钮时,我要把该gridview每行的textbox的值存入数据库请问该怎么做? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 foreach(GridViewRow gvr in GridView1.Rows){ TextBox t = gvr.FindControl("TextBox1") as TextBox; if(t != null) { //用GridView1.DataKeys[gvr.RowIndex].Value.ToString()得到主键列 //根据t.Text向数据库里插入 }} 我博客中的一篇文章,你看看,或许有点帮助:====================假如你在gridview中添加一个模板列,并 在模板列中存放了一个dropdownlist控件。那么,问题就是:你如何去操作这个dropdownlist控件????//对于gridview控件: System.Web.UI.WebControls.GridViewRow rows = (GridViewRow)((Control)sender).Parent.Parent;//获取对于ui层次结构中服务器控件的父控件的父控件的引用 DropDownList list = (DropDownList)rows.FindControl("DropDownList1");//对于datagrid控件: System.Web.UI.WebControls.DataGridItem item = (DataGridItem)((Control)sender).Parent.Parent;//获取对于ui层次结构中服务器控件的父控件的父控件的引用 DropDownList list = (DropDownList)rows.FindControl("DropDownList1");其实运用的就是findcontrol方法。System.Web.UI.WebControls.GridViewRow rows = (GridViewRow)((Control)sender).Parent.Parent;//获取对于ui层次结构中服务器控件的父控件的父控件的引用 amandag 我刚用你的方法调试了下, int a = Convert.ToInt32(t.Text.ToString()); 但是当这句执行完后,变量a的值仍是页面初始化的值 怎么回事? 你的GridView绑定的时候,是否进行了回传页的判断? protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //绑定你的GridView } } 谢谢你了,在网上找了半天都没找到答案,你一下就给解决了!牛XXX! 求救: c#调用 c的dll 有谁知道这什么原因造成的呢? C#索引器问题 求一更新发布程序思路 再求--如何在后台得到Label控件的Text值 一段时间内,多终端同时登陆并提取资料,优化策略探讨 请问做一个共享上网的软件(NAT方式)需要用什么技术 vs 2003 怎么为程序配置config文件? Autofac的问题 BINGDINGSOUCE的使用方法,高分请教!在线等待! 数据集问题。DataTime主键不能筛选数据 VC到C#,变量到对象。。
{
TextBox t = gvr.FindControl("TextBox1") as TextBox;
if(t != null)
{
//用GridView1.DataKeys[gvr.RowIndex].Value.ToString()得到主键列
//根据t.Text向数据库里插入
}
}
====================假如你在gridview中添加一个模板列,并 在模板列中存放了一个dropdownlist控件。那么,问题就是:你如何去操作这个dropdownlist控件????//对于gridview控件: System.Web.UI.WebControls.GridViewRow rows = (GridViewRow)((Control)sender).Parent.Parent;//获取对于ui层次结构中服务器控件的父控件的父控件的引用
DropDownList list = (DropDownList)rows.FindControl("DropDownList1");//对于datagrid控件: System.Web.UI.WebControls.DataGridItem item = (DataGridItem)((Control)sender).Parent.Parent;//获取对于ui层次结构中服务器控件的父控件的父控件的引用
DropDownList list = (DropDownList)rows.FindControl("DropDownList1");其实运用的就是findcontrol方法。
System.Web.UI.WebControls.GridViewRow rows = (GridViewRow)((Control)sender).Parent.Parent;//获取对于ui层次结构中服务器控件的父控件的父控件的引用
但是当这句执行完后,变量a的值仍是页面初始化的值
怎么回事?
{
if (!IsPostBack)
{
//绑定你的GridView
}
}
牛XXX!