我在gridview里增加了两列 一列是一个RadioButtonList,另一列是一个DropDownListpageload里写了
if (!IsPostBack)
{}在获取gridview的选取行的值时,  RadioButtonList的值可以获取,但是DropDownList的值是"未将对象引用设置到对象的实例"为什么取不到DropDownList的值啊.

解决方案 »

  1.   

     DropDownList生成语句
    for (i = 1; i <= bdsm; i++)
                {                DDownList1.Items.Add(new ListItem(i.ToString(), i.ToString()));
                }获取DropDownList值的语句
     DropDownList DDownList1 = (DropDownList)row.FindControl("DropDownList");
      ssbd = DDownList1.SelectedItem.ToString();
      

  2.   

    DropDownList生成语句
    for (i = 1; i <= bdsm; i++)
      {  DDownList1.Items.Add(new ListItem(i.ToString(), i.ToString()));
      }
    写在哪....
      

  3.   

    获取DropDownList值的语句
     DropDownList DDownList1 = (DropDownList)row.FindControl("DropDownList");
      ssbd = DDownList1.SelectedItem.Text.ToString();
      

  4.   

     protected void list_SelectedIndexChanged(object sender, EventArgs e)
        {
            RadioButtonList rblidea = (RadioButtonList)row.FindControl("rblidea");
            if (rblidea.Items[0].Selected == true)
            {
                sftbr = "1";
            }
            else
            {
                sftbr = "0";
            }
            DropDownList DDownList1 = (DropDownList)row.FindControl("DropDownList");
            ssbd = DDownList1.SelectedItem.Text.ToString();}写在gridview的SelectedIndexChanged事件里
      

  5.   

    RadioButtonList rblidea = (RadioButtonList)row[i].FindControl("rblidea");
      

  6.   

    RadioButtonList的值是可以获取的,倒是DropDownList的值没办法获取.
      

  7.   

    你循环的哪个i的值应该是空的,你response出来看一下吧,应该是没有值的
      

  8.   

    ssbd = DDownList1.Text.ToString();
      

  9.   

    调试看看SQL取到  对象集合了么..如果没有SQL除了问题,如果有,就是给值的时候出了问题
      

  10.   

    取不到是对的!!!! 下拉的ID已经被 GRIDVIEW改变了!!你看HTML代码就知道了!既然ROW能取的到,就能ROW.ITEM 取到 下拉所在的 列! 然后再转换 DropDownList
      

  11.   

    你那样找肯定是错的  这样去找GridView1.SelectedRow.FindControl("XX");
      

  12.   

    建议用 JS去取值!获取 GRIDVIEW 控件, GRIDVIEW
    document.getElementById("GRIDVIEW1").ROW 去取值
      

  13.   

    建了一个名为list的griview控件
    有list_RowDataBound1和list_SelectedIndexChanged两件事件
     protected void list_RowDataBound1(object sender, GridViewRowEventArgs e)
        {
            e.Row.Height = 30;
            DataRowView drvSfhg;
            string strHg;
            int i;
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //外观样式
                if (e.Row.RowIndex % 2 == 0)
                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=\"" + e.Row.Style["BACKGROUND-COLOR"] + "\"");
                else
                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=\"#EFF3F7\"");
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor=\"#D1DDF1\"");
                //编号 
                e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();            drvSfhg = (DataRowView)e.Row.DataItem;
                strHg = drvSfhg.Row["sfhg"].ToString();            if (strHg == "1")
                {
                    e.Row.Cells[4].Text = "是";
                    e.Row.Cells[4].ForeColor = Color.Red;
                }
                else
                {
                    e.Row.Cells[4].Text = "否";
                }                        RadioButtonList rblidea = (RadioButtonList)e.Row.FindControl("rblidea");
                HiddenField hditem = (HiddenField)e.Row.FindControl("hditem");
                DropDownList DDownList1 = (DropDownList)e.Row.FindControl("DDownList1");            if (hditem.Value == "1")
                {
                    rblidea.Items[0].Selected = true;            }
                else
                {
                    rblidea.Items[1].Selected = true;
                }
                //生成标段选择列表
                for (i = 1; i <= bdsm; i++)          
                {
                    DDownList1.Items.Add(new ListItem(i.ToString(), i.ToString()));
                                  
                }
            }
        }-------------------------------------------------------------------------
    protected void list_SelectedIndexChanged(object sender, EventArgs e)
        {
            string zbggbm, qybm, ssbd, sftbr;
            zbggbm = Request.QueryString["sgzbbm"].ToString();
            GridViewRow row = list.SelectedRow;        
            qybm = row.Cells[3].Text.Trim();        RadioButtonList rblidea = (RadioButtonList)row.FindControl("rblidea");
            if (rblidea.Items[0].Selected == true)
            {
                sftbr = "1";
            }
            else
            {
                sftbr = "0";
            }
            DropDownList DDownList1 = (DropDownList)row.FindControl("DropDownList");             
            ssbd = DDownList1.Text.ToString();     
    }
      

  14.   

    我把取值的那段改成了
    DropDownList DDownList1 = (DropDownList)list.SelectedRow.Cells[7].FindControl("DropDownList");              ssbd = DDownList1.Text.ToString();     
    还是一样的为空
      

  15.   

    DropDownList DDownList1 = (DropDownList)row.FindControl("DDownList1");  
      ssbd = DDownList1.Text.ToString();
      

  16.   

    试试这段:
    DropDownList DDownList1 = (DropDownList)list.SelectedRow.Cells[7].FindControl("DDownList1");   
    if(DDownList1 !=null)
    {
    ssbd = DDownList1.Text.ToString();   
    }
    else
    {
         //write a log
    }
      

  17.   

    我之前也是这个错误,但是后来我自己解决了,是取值的问题,对DropDownList来说,他是一个很特别的类,他的实例不是在gridview里面,有时间找到我的给你看看,只要对他先填充数据。