一个GRIDVIEW的模板列中放入一个DROPDOWNLIST控件ddltype,并且是放在编辑项模板中,我已绑定了它的值,可是在返回的时候,它总是返回第一个值!我是用以下代码的,各位帮我看一下
cn.Open();
string sql = "select * from tbSubType";
SqlDataAdapter da = new SqlDataAdapter(sql,cn);
DataSet ds = new DataSet();
da.Fill(ds,"tbSubType");
this.GridView1.DataSource = ds.Tables["tbSubType"];
this.GridView1.DataBind();
this.GridView1.DataKeyNames = new string[] { "stID" };
if (this.GridView1.EditIndex > -1)
{
for (int i = 0; i <= this.GridView1.Rows.Count - 1; i++)
{
DropDownList ddl = (DropDownList)this.GridView1.Rows[i].FindControl("ddltype");
DataRowView drv = ds.Tables["tbSubType"].DefaultView[i];
ddl.Items.FindByValue(drv["stParentID"].ToString()).Selected = true;
}
}
cn.Close();
如果ddltype不在编辑项中,此代码可以返回正确值,我现在郁闷的是在编辑项模板中,如何让它返回正确值????我的代码该如何修正???
cn.Open();
string sql = "select * from tbSubType";
SqlDataAdapter da = new SqlDataAdapter(sql,cn);
DataSet ds = new DataSet();
da.Fill(ds,"tbSubType");
this.GridView1.DataSource = ds.Tables["tbSubType"];
this.GridView1.DataBind();
this.GridView1.DataKeyNames = new string[] { "stID" };
if (this.GridView1.EditIndex > -1)
{
for (int i = 0; i <= this.GridView1.Rows.Count - 1; i++)
{
DropDownList ddl = (DropDownList)this.GridView1.Rows[i].FindControl("ddltype");
DataRowView drv = ds.Tables["tbSubType"].DefaultView[i];
ddl.Items.FindByValue(drv["stParentID"].ToString()).Selected = true;
}
}
cn.Close();
如果ddltype不在编辑项中,此代码可以返回正确值,我现在郁闷的是在编辑项模板中,如何让它返回正确值????我的代码该如何修正???
也就是那個互動屬性吧!!
如 ((TextBox)...controls[0]).Text