问题描述:
GridView1绑定了检索出来的数据库的字段,其中有一个字段PID。根据用户的需求,可能在检索时检索到了PID字段,从而绑定到了GridView1,也有可能没有检索到,从而没有在GridView1里面。
现在的问题是,如果GridView1里面有PID字段,则我想让用户点击一下PID字段的某个内容,就能读出这个内容,读到TextBox1.text里面,并且执行一段代码——dhfgfgfhgfjdf。
求上述问题的代码。或设置。
在线等,问题描述不清楚的地方请问我。
有老各位!!
GridView1绑定了检索出来的数据库的字段,其中有一个字段PID。根据用户的需求,可能在检索时检索到了PID字段,从而绑定到了GridView1,也有可能没有检索到,从而没有在GridView1里面。
现在的问题是,如果GridView1里面有PID字段,则我想让用户点击一下PID字段的某个内容,就能读出这个内容,读到TextBox1.text里面,并且执行一段代码——dhfgfgfhgfjdf。
求上述问题的代码。或设置。
在线等,问题描述不清楚的地方请问我。
有老各位!!
解决方案 »
- 高手们帮忙!关于DataReader未关闭的问题。
- 泛型参数 和类型约束
- ASP.NET 按钮自动跳转的问题
- sql server 创建作业问题!
- oracleConnection.open() 未引用的对象实例的问题
- 请问csdn社区的静态页面是哪种解决方法
- 请教:水晶报表显示页,为什么总是左侧空出七八厘米宽的空白?
- 菜鸟发问,不知道错在哪里,大侠进来看一下
- 求助.net windows应用程序问题!!
- var file = document.getElementById("div1").firstChild; 此脚本为什么会在IE10 上失效 ? 100分敬上
- 请教:asp.net网站,怎样根据URL地址自动执行某一程序?
- ASP.NET中怎么做文件下载统计?
protected void CPSGridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
string PID= string.Empty; if (e.Row.RowType == DataControlRowType.DataRow)
{ PID= e.Row.Cells[0].Text.Trim(); e.Row.Cells[3].Text = "<a href=\"javascript:JSFunction('" + PID + "')\">" + PID + "</a>";
}
}
function JSFunction(PID)
{
document.getElementById('TextBox1').value = PID;
}
如有疑問請跟帖
//請將Cells[]中的index對應為你自己的Index,
PID= e.Row.Cells[0].Text.Trim(); e.Row.Cells[3].Text = "<a href=\"javascript:JSFunction('" + PID + "')\">" + PID + "</a>";
点击pid字段某个内容,是用什么方法选择
求代码,最好给点注释。有劳各位。完了再加分。
{
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的值
}
}
参考
{
if (e.Row.RowType == DataControlRowType.DataRow)
if (e.Row.FindControl("Button1") != null)
{
Button btn = (Button)e.Row.FindControl("Button1");
btn.Click += new EventHandler(btn_Click);
}
}
} private void btn_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
GridViewRow gvr = (GridViewRow)btn.Parent.Parent;
string pk = GridView1.DataKeys[gvr.RowIndex].Value.ToString(); this.Text1.Text = pk;
}