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(); }
protected void [color=#FF0000]ddlSubCht[/color]_SelectedIndexChanged(object sender, EventArgs e) { for (int i = 0; i < gvCategories.Rows.Count; i++) { DropDownList ddl = (DropDownList)gvCategories.Rows[i].FindControl("[color=#FF0000]ddlSubCht[/color]");//问题1:在Debug下发现不能找到控件 int ddlint = Convert.ToInt32(ddl.SelectedValue);//问题2:提示"未将对象引用设置到对象的实例" int key = (int)gvCategories.DataKeys[i].Value;//问题3:总是返回的同一个值.我想返回的是每行对应的DataKeys lbl.Text= ddlint+"_"+key+"_"+isSingle.ToString();//输出 } }