3編輯時,在同一行中顯示下拉列表。ASP.NET編輯GridView行
當1 dropdownlist有一個選擇,其他2應該去索引0(空的)。我的代碼
例子:
<asp:TemplateField HeaderText="Project" SortExpression="Project">
<ItemTemplate>
<%#Eval("Project") %>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ProjectDropDownList" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ProjectDropDownList_Changed" AppendDataBoundItems="true"
DataSourceID="ProjectDataSource" DataTextField="navn" DataValueField="navn">
<asp:ListItem>-- choose one --</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
我的SelectionChanged,甚至處理:
protected void ProjektDropDownList_SelectionChanged(object sender, EventArgs e)
{
DropDownList project = (DropDownList) GridView1.Rows[GridView1.SelectedIndex].FindControl("ProjectDropDownList");
DropDownList kunde = (DropDownList)GridView1.Rows[GridView1.SelectedIndex].FindControl("KundeDropDownList");
DropDownList øvrige = (DropDownList)GridView1.Rows[GridView1.SelectedIndex].FindControl("ØvrigeDropDownList");
if(project.SelectedIndex >= 0 && kunde != null && øvrige != null) {
kunde.SelectedIndex = 0;
øvrige.SelectedIndex = 0;
}
}
我在嘗試在同一行中獲取其它控制器,一個空指針... 我該如何解決?
空指針爲哪個對象? – gbs 2011-05-22 13:46:02
DropDownList的空指針我試圖到達UpdatingEvent/EditingEvent的外部。 – KristianB 2011-05-22 15:28:38