怎么获得GridView某一行某一列的值???急,谢谢!!!

guoziwumingzi 2009-05-04 04:56:18
GridView里面有一个修改按钮,点击此按钮时修改GridView里的某一列,但是现在不知道怎么获取此列的值,希望各位大虾指点,谢谢!!!
...全文
3887 27 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
27 条回复
切换为时间正序
请发表友善的回复…
发表回复
haoyunlxj2012 2012-05-10
  • 打赏
  • 举报
回复
gridview.rows[0].cells[0].text
lsd123 2009-05-05
  • 打赏
  • 举报
回复
.
tulong403 2009-05-05
  • 打赏
  • 举报
回复
答案正确 加十分
peng_weida 2009-05-05
  • 打赏
  • 举报
回复
百度 GOOGLE 一搜索 GridView的用法
沉序员 2009-05-05
  • 打赏
  • 举报
回复























我的分啊,你現在說沒有?日啊?
E_wait 2009-05-05
  • 打赏
  • 举报
回复
河蟹社会
CloudOfFly 2009-05-05
  • 打赏
  • 举报
回复
都已经说的够明了了 我不用说了
springbell 2009-05-05
  • 打赏
  • 举报
回复
沉序员 2009-05-05
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zhang_delphi 的回复:]
gridview.rows[0].cells[0].text 這就是值了。有特別的(如模板列 就用FINDCONTROL(‘NAME’))
[/Quote]

[Quote=引用 18 楼 guoziwumingzi 的回复:]
我用gridview.rows[0].cells[0].text已经 写好了,给Rows循环了一下,可是没有那么多分送人啊!
[/Quote]


分還不給我,還說了我一頓真是個DIAO 毛啊?現在又說沒分了。
emoheshang 2009-05-04
  • 打赏
  • 举报
回复
gridview1.Rows[i].Cells[j].Text.Trim();
SK_Aqi 2009-05-04
  • 打赏
  • 举报
回复
楼主不用愁了,送给我了
看吧我关注你的帖子了啊
guoziwumingzi 2009-05-04
  • 打赏
  • 举报
回复
我用gridview.rows[0].cells[0].text已经 写好了,给Rows循环了一下,可是没有那么多分送人啊!
沉序员 2009-05-04
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 SK_Aqi 的回复:]
引用 2 楼 zhang_delphi 的回复:
gridview.rows[0].cells[0].text 這就是值了。有特別的(如模板列 就用FINDCONTROL(‘NAME’))


支持
[/Quote]
這個已經說得很全面了。還不給它的30分

























cntenger 2009-05-04
  • 打赏
  • 举报
回复

((TextBox)GridView1.Rows[e.RowIndex].FindControl("tbClassId")).Text
SK_Aqi 2009-05-04
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zhang_delphi 的回复:]
gridview.rows[0].cells[0].text 這就是值了。有特別的(如模板列 就用FINDCONTROL(‘NAME’))
[/Quote]

支持
asdf4525qd 2009-05-04
  • 打赏
  • 举报
回复
这里没有用参数做,抱歉下
asdf4525qd 2009-05-04
  • 打赏
  • 举报
回复
这是一段完整的gridview操作代码,你自己好好看下吧,各位高手们也请指教下


protected void Changing(object sender,GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
bind(strCon);
}
protected void Download(object sender, GridViewCommandEventArgs e)
{
int id = 0;
if (e.CommandName == "download")
{
id = System.Convert.ToInt32(e.CommandArgument.ToString());

string strSql = "select filepath from normal_info_deploy where info_id = " + ((Label)GridView1.Rows[id].Cells[0].FindControl("NoItem")).Text;
if (ConnectDB() == "0")
{
SqlCommand sqlCmd = conn.CreateCommand();
sqlCmd.CommandText = strSql;
SqlDataReader thisReader = sqlCmd.ExecuteReader();
string tempvar = "";
try
{
while (thisReader.Read())
{
tempvar = thisReader[0].ToString();
}
thisReader.Close();
}
catch
{
thisReader.Close();
}
string name = Server.MapPath(tempvar);
string[] filename = name.Split('\\');
//name += "." +
FileInfo aFile = new FileInfo(name);
if (File.Exists(name))
{
//构建html表头
Response.Clear();
Response.ClearHeaders();
Response.BufferOutput = false;
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-disposition", "attachment;filename=" + filename[filename.Length - 1]);
Response.AddHeader("Content-Length", aFile.Length.ToString());
Response.WriteFile(name);
Response.Flush();
Response.End();
}
else
{
Response.Write("<script>alert('服务器未能找到相应文件,请咨询管理员')</script>");
}
}
else
{
Response.Write("<script>alert('与服务器连接失败')</script>");
}
}
else if (e.CommandName == "del")
{
id = System.Convert.ToInt32(e.CommandArgument.ToString());

string strSql = "select filepath from normal_info_deploy where info_id = " + ((Label)GridView1.Rows[id].Cells[0].FindControl("NoItem")).Text;
if (tempdb.ConnectDB() == "0")
{
string Sql;
Sql = "update normal_info_deploy set filepath = '_',deployfilename = '_' where info_id = " + ((Label)GridView1.Rows[id].Cells[0].FindControl("NoItem")).Text;

if (tempdb.ExecuteSql(Sql) == 0)
{
Response.Write("<script>alert('删除成功')</script>");
}
}
else
{
Response.Write("<script>alert('无法连接数据库')</script>");
}
if (ConnectDB() == "0")
{
SqlCommand sqlCmd = conn.CreateCommand();
sqlCmd.CommandText = strSql;
SqlDataReader thisReader = sqlCmd.ExecuteReader();
string tempvar = "";
try
{
while (thisReader.Read())
{
tempvar = thisReader[0].ToString();
}
thisReader.Close();
}
catch
{
thisReader.Close();
}
string name = Server.MapPath(tempvar);
tempdb.DeleteFile(name);
}
bind(strCon);
}


}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
bind(strCon);
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
if (tempdb.ConnectDB() == "0")
{
string strSql;
strSql = "delete from normal_info_deploy where info_id = " + GridView1.DataKeys[e.RowIndex].Value.ToString();

if (tempdb.ExecuteSql(strSql) == 0)
{
Response.Write("<script>alert('删除成功')</script>");
}
}
else
{
Response.Write("<script>alert('无法连接数据库')</script>");
}
bind(strCon);
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
bind(strCon);
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
if (tempdb.ConnectDB() == "0")
{
string strSql;
((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].FindControl("tittle"))).Text.ToString();
((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].FindControl("info"))).Text.ToString();
((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].FindControl("deployer"))).Text.ToString();
((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].FindControl("obj"))).Text.ToString();
strSql = "update normal_info_deploy set info_title = '" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].FindControl("tittle"))).Text.ToString() + "'" + "," +
"info_cont = '" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].FindControl("info"))).Text.ToString() + "'," +
"deployer = '" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].FindControl("deployer"))).Text.ToString() + "'," +
"deploy_object = '" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].FindControl("obj"))).Text.ToString() + "' where info_id = " + GridView1.DataKeys[e.RowIndex].Value.ToString();

if (tempdb.ExecuteSql(strSql) == 0)
{
Response.Write("<script>alert('修改成功')</script>");
}
}
}
catch
{
Response.Write("<script>alert('修改失败')</script>");
}
GridView1.EditIndex = -1;
bind(strCon);
}
public void bind(string str)
{
if (tempdb.ConnectDB() == "0")
{
string strCondition = str;
DataSet set = new DataSet();
set = tempdb.GetNormalDeployInfo(strCondition);
GridView1.DataSource = set;

GridView1.DataKeyNames = new string[] { "info_id" };
GridView1.DataBind();
int j = 0;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
if (set.Tables[0].Rows[i].ItemArray[10].ToString() == "_")
{
((LinkButton)GridView1.Rows[i].FindControl("download")).Visible = false;
((LinkButton)GridView1.Rows[i].FindControl("delete")).Visible = false;
}
if (set.Tables[0].Rows[i].ItemArray[10].ToString() == null || set.Tables[0].Rows[i].ItemArray[10].ToString() == "")
{
break;
}
}
}
}
}
沉序员 2009-05-04
  • 打赏
  • 举报
回复
你能做什麼的時候,可能我已經死了
guoziwumingzi 2009-05-04
  • 打赏
  • 举报
回复
我用二楼的可以获取,但是在第二行的时候就不知道怎么办了,要循环~~~
guoziwumingzi 2009-05-04
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 HappyZhuNIng 的回复:]
如果时普通列:
gridview.rows[i].cells[j].text
如果时模板列,譬如模板列包含TextBoxName,则
TextBox tb = (TextBox)[Convert.ToInt32(e.CommandArgument)].FindControl("TextBoxName")
然后
tb.text 就ok了
[/Quote]gridview.rows[i].cells[j].text 这里的循环还是看不懂,呵呵。是新手,还望大家多多包含~~
加载更多回复(7)

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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