gridview里的部分代码:
<asp:TemplateField HeaderText="绑定的会议室">
<ItemStyle Width="100px" />
<ControlStyle Width="100px" />
<EditItemTemplate>
<asp:ListBox ID="ListBox1" runat="server" SelectionMode="Multiple"></asp:ListBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lb_state" runat="server" Text='<%# Bind("room_name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="更新" ShowEditButton="True" CausesValidation="False" ItemStyle-Width="120px">
</asp:CommandField> CODE代码:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string sql3 = "select room_id,room_name from room_list";
ListBox ListBox2 = (ListBox)e.Row.FindControl("ListBox1");
ListBox2.DataSource = dataOperate.getDataset(sql3);
ListBox2.DataTextField = "room_name";
ListBox2.DataValueField = "room_id";
ListBox2.DataBind();
LinkButton lkbDel = (LinkButton)e.Row.FindControl("lbtnDelete");
lkbDel.Attributes.Add("OnClick", "javascript:return confirm('确定要删除该管理员吗?')");
Label lb1 = (Label)e.Row.Cells[0].FindControl("lable");
lb1.Text = (GridView1.PageIndex * GridView1.PageSize + e.Row.RowIndex + 1).ToString();
}
}错误提示:未将对象引用设置到对象的实例
源错误:
行 74: string sql3 = "select room_id,room_name from room_list";
行 75: ListBox ListBox2 = (ListBox)e.Row.FindControl("ListBox1");
行 76: ListBox2.DataSource = dataOperate.getDataset(sql3);行 77: ListBox2.DataTextField = "room_name";
行 78: ListBox2.DataValueField = "room_id";76行出错
<asp:TemplateField HeaderText="绑定的会议室">
<ItemStyle Width="100px" />
<ControlStyle Width="100px" />
<EditItemTemplate>
<asp:ListBox ID="ListBox1" runat="server" SelectionMode="Multiple"></asp:ListBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lb_state" runat="server" Text='<%# Bind("room_name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="更新" ShowEditButton="True" CausesValidation="False" ItemStyle-Width="120px">
</asp:CommandField> CODE代码:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string sql3 = "select room_id,room_name from room_list";
ListBox ListBox2 = (ListBox)e.Row.FindControl("ListBox1");
ListBox2.DataSource = dataOperate.getDataset(sql3);
ListBox2.DataTextField = "room_name";
ListBox2.DataValueField = "room_id";
ListBox2.DataBind();
LinkButton lkbDel = (LinkButton)e.Row.FindControl("lbtnDelete");
lkbDel.Attributes.Add("OnClick", "javascript:return confirm('确定要删除该管理员吗?')");
Label lb1 = (Label)e.Row.Cells[0].FindControl("lable");
lb1.Text = (GridView1.PageIndex * GridView1.PageSize + e.Row.RowIndex + 1).ToString();
}
}错误提示:未将对象引用设置到对象的实例
源错误:
行 74: string sql3 = "select room_id,room_name from room_list";
行 75: ListBox ListBox2 = (ListBox)e.Row.FindControl("ListBox1");
行 76: ListBox2.DataSource = dataOperate.getDataset(sql3);行 77: ListBox2.DataTextField = "room_name";
行 78: ListBox2.DataValueField = "room_id";76行出错
if (e.Row.RowState == DataControlRowState.Edit)
{
ListBox ListBox2 = (ListBox)e.Row.FindControl("ListBox1");
..
}