本文介绍了从gridview Cell中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void gvDetails_RowUpdating(object sender,GridViewUpdateEventArgs e)

{

int userid = Convert.ToInt32(gvDetails.DataKeys [e.RowIndex] .Value .ToString());

string username = gvDetails.DataKeys [e.RowIndex] .Values [UserName]。ToString();

TextBox txtcity =(TextBox )gvDetails.Rows [e.RowIndex] .FindControl(txtcity);

TextBox txtDesignation =(TextBox)gvDetails.Rows [e.RowIndex] .FindControl(txtstate);


con.Open();

SqlCommand cmd = new SqlCommand(更新Employee_Details set City =''+ txtcity.Text +'',Designation =' '+ txtDesignation.Text +''其中UserId =+ userid,con);

cmd.ExecuteNonQuery();

con.Close();



lblresult.Text =用户名+详细信息已成功更新;

gvDetails.EditIndex = - 1;

BindEmployeeDetails();

}





i有一个gridview ID = gv_Details。当处于编辑模式时,所需的单元格更改为文本框..

我无法理解上面的 BOLD 代码..这是一个演员吗?如果是的话,为什么我们以这种方式投射从特定单元格中获取数据..?

我也想知道 RowBound事件的使用...以及何时和我们如何使用它.. ??

谢谢。

解决方案



protected void gvDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int userid = Convert.ToInt32(gvDetails.DataKeys[e.RowIndex].Value.ToString());
string username = gvDetails.DataKeys[e.RowIndex].Values["UserName"].ToString();
TextBox txtcity = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtcity");
TextBox txtDesignation = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtstate");

con.Open();
SqlCommand cmd = new SqlCommand("update Employee_Details set City=''" + txtcity.Text + "'',Designation=''" + txtDesignation.Text + "'' where UserId=" + userid, con);
cmd.ExecuteNonQuery();
con.Close();

lblresult.Text = username + " Details Updated successfully";
gvDetails.EditIndex = -1;
BindEmployeeDetails();
}


i have a gridview ID=gv_Details .and when in edit mode the required cell changes to Textbox ..
I am unable to understand above BOLD code ..is this a casting ? if yes , why do we cast in this way to fetch the data from a particul cell ..?
I also want to know use of RowBound Event.. and when and how do we use it ..??
Thank You .

解决方案



这篇关于从gridview Cell中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-09 14:54