ListItem item = new ListItem();
item.Text = Session["w"].ToString();
item.Value = Session["eid"].ToString();
DropDownList s = (DropDownList)GridView1.FindControl("DropDownList1");
s.Items.Add(item);报错为:最后一句
未将对象引用设置到对象的实例。请问如何解决
item.Text = Session["w"].ToString();
item.Value = Session["eid"].ToString();
DropDownList s = (DropDownList)GridView1.FindControl("DropDownList1");
s.Items.Add(item);报错为:最后一句
未将对象引用设置到对象的实例。请问如何解决
解决方案 »
- 十万火急“/”应用程序中的服务器错误。未将对象引用设置到对象的实例。
- ASP.NET MVC新手求教.如何多个cshtml使用同一个ActionResult提供数据?
- 数字报纸是否有专业的系统?还是就是各自打造了CMS平台?每一家数字报纸的相似度很高啊
- 打开新页面
- 在此对自己近阶段的工作作一个小小总结
- 我在WINFORM程序中,用代码写数据到EXCEL表格时,会弹出确认框,我想不要弹出确认框,就能直接保存数据。。怎么做???
- 怎么使用TEEEVIEW作权限菜单
- 我用ajax做上传文件在.ashx文件怎么获取File的个数
- 有谁知道有象OICQ那样的下拉控件下载地址,可以用在ASP.NET中
- Response.Redirect("docs.asp?" + Request.QueryString)语句怎样从ASP移植到asp.net?
- css样式
- 接着上个问题问
如果你是在gridview_RowDataBound事件中
那么试试这样查找控件
if(e.Row.RowType==DataControlRowType.DataRow)
{
DropDownList ddList = e.Row.FindControl("DropDownList1") as DropDownList;
}
要在row上查找,如GridView1.Rows[0].FindControl("DropDownList1");
DropDownList ddList.Items.Add(item);
也不行能说能帮忘记改成功呀
ddlist.Items.Add(item);改成这样后一样报错索引超出范围。必须为非负值并小于集合大小。
参数名: index
还有就是试用session时要判断下
if(Session["w"]!=null &&Session["eid"]1=null)
{
....
}
CS0117: “System.EventArgs”并不包含“RowIndex”的定义
protected void gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddl = e.Row.FindControl("DropDownList1") as DropDownList ;
}
}