private void WorkList_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
WorkList.EditItemIndex = e.Item.ItemIndex;
BindGrid();
}<asp:TemplateColumn HeaderText="信息类型">
<ItemTemplate>
<asp:Label id=Label1 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.areaname") %>'>
</asp:Label>
</ItemTemplate>
<DropDownList >
<asp:DropDownList id=housetype runat="server" Width="107px" DataValueField="areaname" DataTextField="areaname" DataSource="<%# BindThehousetype(4) %>">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
public SqlDataReader BindThehousetype(int typeid)
{
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["fc"].ToString());
SqlCommand cmd =new SqlCommand("select areaname,id from area where typeid="+typeid+"", conn);
conn.Open();
return cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
{
WorkList.EditItemIndex = e.Item.ItemIndex;
BindGrid();
}<asp:TemplateColumn HeaderText="信息类型">
<ItemTemplate>
<asp:Label id=Label1 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.areaname") %>'>
</asp:Label>
</ItemTemplate>
<DropDownList >
<asp:DropDownList id=housetype runat="server" Width="107px" DataValueField="areaname" DataTextField="areaname" DataSource="<%# BindThehousetype(4) %>">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
public SqlDataReader BindThehousetype(int typeid)
{
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["fc"].ToString());
SqlCommand cmd =new SqlCommand("select areaname,id from area where typeid="+typeid+"", conn);
conn.Open();
return cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
{
if(e.Item.ItemIndex>-1)
{
ListItem tmp = ((DropDownList)e.Item.FindControl("housetype")).FindByValue(((Label)e.Item.FindControl("Label1")).Text);
if(tmp!=null)tmp.Selected = true;
}
}
{
if(e.Item.ItemIndex>-1)
{
ListItem tmp = ((DropDownList)e.Item.FindControl("housetype")).FindByValue(((Label)e.Item.FindControl("Label1")).Text);
if(tmp!=null)tmp.Selected = true;
}
}
ListItem tmp = ((DropDownList)e.Item.FindControl("housetype")).Items.FindByValue(((Label)e.Item.FindControl("Label1")).Text);未将对象引用设置到对象的实例。