我收到错误消息'对象引用未设置为对象的实例'我的问题是:
你能解释一下这个决议,好像我是一个5岁的人。
ASCX
<asp:GridView ID="gvStaffStatus" runat="server"
DataKeyNames="ID_NUM"
OnRowDataBound="gvStaffStatus_RowDataBound">
<Columns>
<asp:TemplateField ItemStyle-VerticalAlign="Top" HeaderText="Member" SortExpression="Member">
<ItemTemplate>
<asp:Image ID="imgStatus" Width="20px" runat="server" ImageUrl="~/Portlets/CUS/ICS/Portlet.KeepingTabs/available.png" />
<asp:Label ID="lblStatus" runat="server"></asp:Label>
<asp:DropDownList ID="ddlStatus" runat="server" OnSelectedIndexChanged="DdlStatus_SelectedIndexChange" AutoPostBack="true" Visible='<%# SetVisible(Eval("ID_NUM").ToString()) %>'>
<asp:ListItem Selected ="True" Text="Available" Value="1" />
<asp:ListItem Text="Busy" Value="2" />
<asp:ListItem Text="Unavailable" Value="3" />
<asp:ListItem Text="Off" Value="0" />
</asp:DropDownList>
<asp:Label runat="server" Text='<%# Bind("Member") %>' ID="lblMember"></asp:Label><br />
<asp:DropDownList ID="ddlLocation" runat="server" AutoPostBack="true" Visible='<%# SetVisible(Eval("ID_NUM").ToString()) %>'>
<asp:ListItem Selected="True" Text="My Office" Value="MYOFF" />
</asp:DropDownList>
<asp:TextBox Width="300px" ID="tbNote" runat="server" Visible='<%# SetVisible(Eval("ID_NUM").ToString()) %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
这一行似乎正在打破:
string status = ddlStatus.SelectedValue;
这些控件都在GridView中的单个TemplateField内的单个ItemTemplate内部
以下代码全部在我的OnInit方法中(但我也在自定义方法中尝试过):
DropDownList ddlStatus = (DropDownList)gvStaffStatus.FindControl("ddlStatus");
Image imgStatus = (Image)gvStaffStatus.FindControl("imgStatus");
string status = ddlStatus.SelectedValue;
switch (status)
{
case "Available":
imgStatus.ImageUrl = "~/Portlets/CUS/ICS/Portlet.KeepingTabs/available.png";
break;
case "Busy":
imgStatus.ImageUrl = "~/Portlets/CUS/ICS/Portlet.KeepingTabs/busy.png";
break;
case "Unavailable":
imgStatus.ImageUrl = "~/Portlets/CUS/ICS/Portlet.KeepingTabs/unavailable.png";
break;
default:
imgStatus.ImageUrl = "~/Portlets/CUS/ICS/Portlet.KeepingTabs/available.png";
break;
}