日期:2014-05-18 浏览次数:20447 次
protected void ddlSubCht_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 0; i < gvCategories.Rows.Count; i++)
{
DropDownList ddl = (DropDownList)gvCategories.Rows[i].FindControl("ddlSubCht");//问题1:在Debug下发现不能找到控件
int ddlint = Convert.ToInt32(ddl.SelectedValue);//问题2:提示"未将对象引用设置到对象的实例"
int key = (int)gvCategories.DataKeys[i].Value;//问题3:总是返回的同一个值.我想返回的是每行对应的DataKeys
lbl.Text= ddlint+"_"+key+"_"+isSingle.ToString();//输出
}
}
protected void ddlSubCht_SelectedIndexChanged(object sender, EventArgs e) { DropDownList ddl = (DropDownList)sender; int ddlint = Convert.ToInt32(ddl.SelectedValue); int key = (int)gvCategories.DataKeys[(ddl.Parent as GridViewRow).RowIndex].Value; .. }
------解决方案--------------------
foreach (GridViewRow row in this.GvCaseApplyList.Rows) { CheckBox chkPunish = (CheckBox)row.FindControl("chkCaseApply"); id=this.GvCaseApplyList.DataKeys[row.RowIndex][1].ToString(); }
------解决方案--------------------
DropDownList ddl = (DropDownList)gvCategories.Rows[i].FindControl("ddlSubCht");//问题1:在Debug下发现不能找到控件
定位不对吧....你这对应的是第几行...单元格呢?
------解决方案--------------------
DropDownList ddl = gvCategories.Rows[i].FindControl("ddlSubCht") as DropDownList;//
另外还要精确到cell
------解决方案--------------------