protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
NewDataBind();
//未將物件參考設定到物件的實體
DropDownList ddl1 = GridView1.Rows[e.NewEditIndex].FindControl("DropDownList1") as DropDownList;
ddl1.SelectedValue = (GridView1.Rows[e.NewEditIndex].FindControl("HiddenField1") as HiddenField).Value;
DropDownList ddl2 = GridView1.Rows[e.NewEditIndex].FindControl("DropDownList2") as DropDownList;
ddl2.SelectedValue = (GridView1.Rows[e.NewEditIndex].FindControl("HiddenField2") as HiddenField).Value;
}
uj5u.com熱心網友回復:
看看 ddl1 是不是為空uj5u.com熱心網友回復:
<asp:TemplateField HeaderText="用戶型別">
<ItemTemplate>
<asp:Label ID="lblType" runat="server" Text='<%#Bind("UPower") %>' Width="130px"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:HiddenField ID="HiddenField1" Value='https://bbs.csdn.net/topics/<%#Eval("UPower") %>' runat="server" />
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Selected="True" Value="https://bbs.csdn.net/topics/0">管理員</asp:ListItem>
<asp:ListItem Value="https://bbs.csdn.net/topics/1">采購員</asp:ListItem>
<asp:ListItem Value="https://bbs.csdn.net/topics/2">售貨員</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
這個是我的dropdownlist
uj5u.com熱心網友回復:
var ddl = (DropDownList)DetailsView1.Rows[rowIndex].Cells[colIndex].FindControl("DropDownList1");
uj5u.com熱心網友回復:
FindControl 未找到值uj5u.com熱心網友回復:
DropDownList ddl1 = (DropDownList )e.Row.FindControl("DropDownList1");強轉一下試試呢
uj5u.com熱心網友回復:
GridView1系結的資料的方法要寫在!(Page.IsPostBack)里轉載請註明出處,本文鏈接:https://www.uj5u.com/net/94785.html
標籤:ASP.NET
上一篇:C# 關于Thread無法被呼叫
