gridview多选 怎么获取被选中行中某一个字段的值?

tony5566 2009-06-03 03:14:02
如题:
下面是删除按钮下的代码
protected void Button_DeleteAdmin_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvr in GridView1.Rows)
{
CheckBox check = (CheckBox)gvr.FindControl("ItemCheckBox");
if (check.Checked)
{
//写日志文件开始====================================================================
if (Session["BoolLog"].ToString().Trim() == "1")
{
string LogStrMsg = "";
//LogUserName-人员 LogTitle-标题 LogMemo-内容
string LogUserName = "[" + Session["UserName"].ToString().Trim() + "]";
string LogTitle = "删除课程安排表";
string LogMemo = "";//------删除记录的课程名称

log.Insert(LogUserName, LogTitle, LogMemo, out LogStrMsg);

}
//写日志文件结束====================================================================
px.Delete(GridView1.DataKeys[gvr.DataItemIndex].Value.ToString().Trim(), out strMsg);
}
}

GridViewShow();
Session["Msg"] = "<script>alert('删除成功!')</script>";
}

我这段代码要表达的是:选中多行,删除,删除前要将删除人、删除时间、删除什么东西记录到日志中,就是不知道怎么取得选中行对应的课程名称的值,
我是新手,代码贴太多 不好意思 让大家看得不舒服。
...全文
335 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
ToHai 2010-07-13
  • 打赏
  • 举报
回复
jfjfjfjfjfjfjfjfjf
tony5566 2009-06-03
  • 打赏
  • 举报
回复
不知道有没有其他办法 对net很不熟悉
tony5566 2009-06-03
  • 打赏
  • 举报
回复
暂时没找其他方法 写了个sql 根据id找到课程名称 再填充给日志
用惯delphi 一下子转不过来
luafie 2009-06-03
  • 打赏
  • 举报
回复
遍历GV里面的控件。找到它。
tony5566 2009-06-03
  • 打赏
  • 举报
回复
苦闷 还不行
outou 2009-06-03
  • 打赏
  • 举报
回复
试试下面的代码,代码来自http://bingning.net/free/source/datagrid/selectedstringincell.html

[C#]

// Tabel样式取得
DataGridTableStyle ts;
ts = DataGrid1.TableStyles["DataTable1"];

//被选择的列取得
int cn = DataGrid1.CurrentCell.ColumnNumber;

// DataGridTextBoxColumn取得
DataGridTextBoxColumn cs =
(DataGridTextBoxColumn) ts.GridColumnStyles[cn];

// TextBox取得
TextBox tb = cs.TextBox;

//被选择的字符串取得
Console.WriteLine(tb.SelectedText);


cpio 2009-06-03
  • 打赏
  • 举报
回复
那列是用的模板吗?你可以看看网页源码,是不是数据在<td></td>里面,如果<td></td>里面还有标签,可以通过FindControl方式找出来

实在不行,从数据源下手,知道是哪一行数据了,肯定知道那行的第几个值吧?
deconding 2009-06-03
  • 打赏
  • 举报
回复

foreach (DataRow dr in dataGridView1.SelectedRows)
{
string col1 = dr[0].ToString(); // 这是每行第一列的值
string col2 = dr[1].ToString(); // 这是每行第二列的值
string col3 = dr[2].ToString(); // 这是每行第三列的值

}
tony5566 2009-06-03
  • 打赏
  • 举报
回复
gvr.Cells[2].Text 一开始就是这样赋值的 但是监视gvr.Cells[2].Text 是null
tony5566 2009-06-03
  • 打赏
  • 举报
回复
删除操作是写存储过程的 px.Delete里执行
cpio 2009-06-03
  • 打赏
  • 举报
回复
比如绑定的第3列是课程名称

gvr.Cells[2].Text就可以取出来了
guojh021 2009-06-03
  • 打赏
  • 举报
回复
删除操作可以写存储过程.只把Key传过去搞定.

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧