想取出DataGridView中的某一列的值 在DataGridView 我想取出 选中 的某一列的一个值,请问怎么才能取出来,求高人详细解析! 谢谢啦 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我的意思就是想要一个随机所选中的某一行,然后取出一个int自增长的Id 然后详细查询 好写sql中where条件里,我就是不知道怎么取出来随机某一行的一列的值! Gridview1.Rows[行].cell[列].Text或Gridview.Rows[行号].cell[列号].Value。ToString();如果是当前行:就Gridview.SelectRows[0].cell[列号].Text 或.Value.ToString() 在datagridview的rowenter事件,取出当前行,在找到对应的列取值就可以了。 那行号就用随机数生成,当然随机数的范围不能超过你DataGridView的总行数 dataGridView.CurrentCell就是当前的选中的单元格,取值dataGridView.CurrentCell.Vaule 第一种方法:Record = "图书" + gridviewRow.Cells[1].Text;地二种方法:(gridviewRow.FindControl("Label1") as Label).Text; gridView.rows[randomIndex] 直接这样不可以吗? 只要不超过row的索引就可以 获取行以后 在获取你想要的列的值 string name = DataGridView.Rows[DataGridView.CurrentRow.Index].Cells["Name"].Value.ToString(); protected void Button1_Click(object sender, EventArgs e) { Random ran = new Random(); string str = GridView1.Rows[ran.Next(GridView1.Rows.Count)].Cells[ran.Next(GridView1.Columns.Count)].Text; Response.Write(str + "<br/>");//如果有的列是有控件的话要找出值要用FindControl("")查找。 } protected void Button1_Click(object sender, EventArgs e) { Random ran = new Random(); string str = GridView1.Rows[ran.Next(GridView1.Rows.Count)].Cells[ran.Next(GridView1.Columns.Count)].Text; Response.Write(str + "<br/>");//如果有的列是有控件的话要找出值要用FindControl("")查找。 } c# 中关于内存释放的问题 如何用dllimport调用c写的dll ▲▲▲▲Clickonce 布署烦死人的问题▲▲▲▲ 请教了~~有关弹出窗体的问题? 日本人投降了。 请问“关于IE中拨号上网代理服务器设置问题” 求高手解决一个日期相关的问题 sql简单查询 怎么在picturebox中加入类似百度地图的标注?? winform按比例压缩图片 c# 触发GridView1_SelectedIndexChanged事件不起作用 winfrom中调用一个jsp页面传值问题
获取行以后 在获取你想要的列的值
{
Random ran = new Random();
string str = GridView1.Rows[ran.Next(GridView1.Rows.Count)].Cells[ran.Next(GridView1.Columns.Count)].Text;
Response.Write(str + "<br/>");
//如果有的列是有控件的话要找出值要用FindControl("")查找。
}
{
Random ran = new Random();
string str = GridView1.Rows[ran.Next(GridView1.Rows.Count)].Cells[ran.Next(GridView1.Columns.Count)].Text;
Response.Write(str + "<br/>");
//如果有的列是有控件的话要找出值要用FindControl("")查找。
}