gridview的问题,如何在rowcommand里获取DropDownList的值! 在RowCommand里怎么才能读到GridView的Value值!我在操作当前行时同样到读取到当行里的DropDownList的Value值,还有当前行的主键值,希望哪位仁兄帮我解决下这个问题呀, 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //当前行的主键值 string id = this.GridView1.DataKeys[e.Row.RowIndex]["id"].ToString(); //找到DropDownList DropDownList dropTemp = (DropDownList)e.Row.Cells[0].FindControl("DropDownList1"); 我在RowCommand事件里对当前行进行操作,但同时要在RowCommand事件如何才能读取到当行里的DropDownList的Value值,和当前行的主键值, //当前行的主键值 string id = this.GridView1.DataKeys[e.Row.RowIndex]["id"].ToString(); //找到DropDownList DropDownList dropTemp = (DropDownList)e.Row.Cells[0].FindControl("DropDownList1"); 但在RowCommand事件里并不包含对 e.Row.Cells 的定义 GridViewCommandEventArgs 类未包含一个用于指示单击按钮所在行的属性。如果需要知道哪个行引发了事件,请使用 CommandArgument 属性将行的索引传给事件处理方法。所以你要先在RowCreated(其中Test是按钮的CommandName)protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e){ LinkButton addButton ; if (e.Row.RowType == DataControlRowType.DataRow) { addButton = (LinkButton)e.Row.Cells[1].Controls[0]; if (addButton != null) { if (addButton.CommandName== "Test") addButton.CommandArgument = e.Row.RowIndex.ToString(); } }}然后在RowCommand事件中protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e){ if (e.CommandName == "Test") { DropDownList dropTemp = (DropDownList)GridView1.Rows[Convert.ToInt32(e.CommandArgument)].Cells[2].FindControl("dropTemp"); if (dropTemp != null) { Response.Write(dropTemp.Text); } }} c1.c1Zip 深度剖析三层架构,第四部。 受不了了,谁能帮我解决这个问题!!!! 程序图标在托盘区的坐标呢 关于多线程的问题 swfupload部署到IIS上之后文件上传错误 问两个WebBrowser控件的问题 连载,LINQ兵法十四章,5(1of1) 求救啊~~zedgraph鼠标移动并显示相应的X轴和Y轴值鼠标移动的时候,有一条纵轴线跟随鼠标移动,同时显示 准备学C# 和 ASP.net 请教学习内容和顺序 图片拖动实现不了拉 急急急!!!关于将Daset中无源数据表中的数据定性指定数据库的问题
string id = this.GridView1.DataKeys[e.Row.RowIndex]["id"].ToString();
//找到DropDownList
DropDownList dropTemp = (DropDownList)e.Row.Cells[0].FindControl("DropDownList1");
但同时要在RowCommand事件如何才能读取到当行里的DropDownList的Value值,和当前行的主键值,
string id = this.GridView1.DataKeys[e.Row.RowIndex]["id"].ToString();
//找到DropDownList
DropDownList dropTemp = (DropDownList)e.Row.Cells[0].FindControl("DropDownList1");
但在RowCommand事件里并不包含对 e.Row.Cells 的定义
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
LinkButton addButton ;
if (e.Row.RowType == DataControlRowType.DataRow)
{
addButton = (LinkButton)e.Row.Cells[1].Controls[0];
if (addButton != null)
{
if (addButton.CommandName== "Test")
addButton.CommandArgument = e.Row.RowIndex.ToString();
}
}
}然后在RowCommand事件中
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Test")
{
DropDownList dropTemp = (DropDownList)GridView1.Rows[Convert.ToInt32(e.CommandArgument)].Cells[2].FindControl("dropTemp");
if (dropTemp != null)
{
Response.Write(dropTemp.Text);
}
}
}