在编辑RowEditing中如何实例化DropDownList?
直接写
DropDownList ddl=(DropDownList)GridView1.FindControl("DropDownList1");DropDownList DDL1 = (DropDownList)GVW_ShowCard.Rows[e.NewEditIndex].Cells[5].FindControl("DropDownList1");
上面二种写法都不行,但是下面却能取到相应的值,为什么啊?
string strValue = ((HtmlInputHidden)GVW_ShowCard.Rows[e.NewEditIndex].Cells[2].FindControl("Hid1")).Value;
大家是如何写的呢?帮小弟一下吧,谢谢了!:)
直接写
DropDownList ddl=(DropDownList)GridView1.FindControl("DropDownList1");DropDownList DDL1 = (DropDownList)GVW_ShowCard.Rows[e.NewEditIndex].Cells[5].FindControl("DropDownList1");
上面二种写法都不行,但是下面却能取到相应的值,为什么啊?
string strValue = ((HtmlInputHidden)GVW_ShowCard.Rows[e.NewEditIndex].Cells[2].FindControl("Hid1")).Value;
大家是如何写的呢?帮小弟一下吧,谢谢了!:)
解决方案 »
- 【基础问题】用 ExecuteScalar() 取字符串被截断了,怎么解决啊?
- 做网站时遇到的技术难题,前来寻求帮助,有经验的高手来指点一下,谢谢!
- 未能从程序集 "" 中加载类型"ock.Path"
- 数据库联接的怪问题,使用微软企业库
- 请教win2003服务器下如何配置asp.net2.0!!
- 求救 关于继承的问题(来者有分呀)
- 关于DataGrid的问题,超简单,我是新手
- asp.net网站服务器上访问可以删除数据库记录,但是其他机器不能
- ckfinder 服务器无法查看略缩图
- 最近在看Duwamish7的时候有个菜鸟问题,请教大家
- 请问大家做登录验证都用asp.net内置的Login控件和数据库吗?
- 通过e.Row.DataItem 属性引用ProductsRow问题
{
GridViewRow gvr = GridView1.Rows[e.NewEditIndex];
DropDownList ddl = (DropDownList)gvr.Cells[你DropDownList放在列的索引].Controls[0];
string str=ddl.SelectItem.Text;
}
//Controls[0]代表单元格中的控件的索引,0代表第一个控件
{
GVW_ShowCard.EditIndex = e.NewEditIndex;
GridViewRow grv = GVW_ShowCard.Rows[e.NewEditIndex];
DropDownList DDL1 = (DropDownList)grv.Cells[5].Controls[0];//提示这里出错
DDL1.Items.Add(new ListItem("EMS", "1"));//想从表中读取想应的值赋给它
BindCard();
}想用户点击编辑后在RowEditing中取得相应ID值,在数据库中查找相应的值然后给DropDownList赋值,这种如何做的呢?虚心请教了:!)
{
DropDownList ddl = (DropDownList)sender;
for (int i=0; i<= 999; i++)
{
ddl.Items.Add(new ListItem(i.ToString(), i.ToString()));
}
GridViewRow det = (GridViewRow)ddl.NamingContainer;
ddl.SelectedValue = ((DataRowView)det.DataItem)["DispOrder"].ToString();
}
protected void gvResume_JobList_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
if (Page.IsValid)
{
string strDispOrder = ((DropDownList)((GridView)sender).Rows[e.RowIndex].FindControl("ddlDispOrder")).SelectedValue;
e.NewValues["DispOrder"] = strDispOrder;
}
}
protected void GridView3_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow gvr = GridView3.Rows[e.RowIndex];
Button btn = (Button)gvr.Cells[2].FindControl("Button2");
string str=btn.Text;
Response.Write(str);
}
if (((DropDownList)e.Row.FindControl("ddlLb")) != null)
{
DropDownList ddlLb = (DropDownList)e.Row.FindControl("ddlLb");
dbm_lb_dal dallb = new dbm_lb_dal();
DataTable dtLb;
dtLb = dallb.GetList("");
ddlLb.Items.Clear();
ddlLb.DataSource = dtLb;
ddlLb.DataTextField = "LBMC";
ddlLb.DataValueField = "LBID";
ddlLb.DataBind();
ddlLb.Items.Insert(0, new ListItem("", ""));
ddlLb.Items.FindByText(dtLb.Rows[0]["LBMC"].ToString()).Selected = true;
dtLb = null;
dallb = null;
}在RowUpdating事件里取值
string Lbmc = ((DropDownList)gdvXl.Rows[e.RowIndex].FindControl("ddlLb")).SelectedItem.Text;
editing和updating不是一样的哦,前者是编辑状态的激活,后者是编辑确认即更新数据
看来在RowEditing真不好取值啊,hehe
DropDownList ddl=(DropDownList)grdType.Rows[e.NewEditIndex].FindControl("DropDownList1");
string ddlValue= ddl.SelectedValue.ToString().Trim();