0
我在更新sqldatasource或更改FormView模式後,我的下拉列表填充填充有問題。下拉是通過代碼後面的數組創建的。我將發佈下面的代碼片段。直到這些事件發生,下拉按預期進行綁定。C#動態創建dropdownlist沒有綁定後,FormView更新
爲什麼這不起作用的任何援助將是非常棒的。
<asp:FormView ID="FormView1" runat="server" DataKeyNames="ID" DataSourceID="tbl_PreRegistration"
Width="100%" CssClass="c2wForm" DefaultMode="Edit">
<EditItemTemplate>
<asp:DropDownList ID="stateDDL" runat="server" OnSelectedIndexChanged="State_DDL_SelectedIndexChanged"
CausesValidation="false" AutoPostBack="true">
</asp:DropDownList>
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
Text="Update" CssClass="button blue" />
<asp:LinkButton ID="btnReset" runat="server" CausesValidation="False"
Text="Cancel" CssClass="button white" OnClick="btnReset1_Click" />
</ContentTemplate></asp:UpdatePanel>
</EditItemTemplate>
</asp:FormView>
後面的代碼:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
populateStateDDL("stateDDL", "CA");
}
}
protected void populateStateDDL(string DDL_ID, string getCurrentValue)
{
DropDownList strDDL_ID = (DropDownList)FormView1.FindControl(DDL_ID);
ArrayList states = new ArrayList();
strDDL_ID.DataValueField = "Value";
strDDL_ID.DataTextField = "Text";
strDDL_ID.DataSource = formating.GetAllStates();
strDDL_ID.DataBind();
strDDL_ID.SelectedValue = getCurrentValue.ToUpper();
}
什麼_ON這些events_ happends?你只提供了默認的編輯模式,所以如果_problem_引發改變模式,你還應該提供其他模式的aspx/codebehind。順便說一下,'DropDownList'不是動態的,它的DataSource是一個數組,不多也不少。 –