我在gridview里增加了两列 一列是一个RadioButtonList,另一列是一个DropDownListpageload里写了
if (!IsPostBack)
{}在获取gridview的选取行的值时, RadioButtonList的值可以获取,但是DropDownList的值是"未将对象引用设置到对象的实例"为什么取不到DropDownList的值啊.
if (!IsPostBack)
{}在获取gridview的选取行的值时, RadioButtonList的值可以获取,但是DropDownList的值是"未将对象引用设置到对象的实例"为什么取不到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();
for (i = 1; i <= bdsm; i++)
{ DDownList1.Items.Add(new ListItem(i.ToString(), i.ToString()));
}
写在哪....
DropDownList DDownList1 = (DropDownList)row.FindControl("DropDownList");
ssbd = DDownList1.SelectedItem.Text.ToString();
{
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事件里
document.getElementById("GRIDVIEW1").ROW 去取值
有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();
}
DropDownList DDownList1 = (DropDownList)list.SelectedRow.Cells[7].FindControl("DropDownList"); ssbd = DDownList1.Text.ToString();
还是一样的为空
ssbd = DDownList1.Text.ToString();
DropDownList DDownList1 = (DropDownList)list.SelectedRow.Cells[7].FindControl("DDownList1");
if(DDownList1 !=null)
{
ssbd = DDownList1.Text.ToString();
}
else
{
//write a log
}