我有一個下拉列表下拉列表項檢索問題上回發
<asp:DropDownList ID="DropDownListMySubjectz" runat="server">
</asp:DropDownList>
我嘗試在C#來填充這個在代碼隱藏。
HtmlGenericControl divMySubjects = (HtmlGenericControl)GridViewUserSubjects.Rows[Convert.ToInt32(e.CommandArgument)].FindControl("divMySubjects");
divMySubjects.Style["display"] = "block";
DropDownList mySubjects = (DropDownList)GridViewUserSubjects.Rows[Convert.ToInt32(e.CommandArgument)].FindControl("DropDownListMySubjectz");
UpdatePanel mySubjectsPanel = (UpdatePanel)GridViewUserSubjects.Rows[Convert.ToInt32(e.CommandArgument)].FindControl("UpdatePanelRequestAction");
mySubjects.DataSource = ProfileDataAccess.GetUserSubjects(Membership.GetUser().ProviderUserKey.ToString()).DefaultView;
mySubjects.DataTextField = "Subjects";
mySubjects.DataValueField = "SubjectId";
mySubjects.DataBind();
mySubjectsPanel.Update();
每件事情都很好。直到回發發生。我嘗試從DRopDownList中獲取項目。但DropDownlist是空的。但是,從代碼隱藏中填充代碼後,它會有價值。並且它也得到相同的下拉預期。
DropDownList DDL = (DropDownList)GridViewUserSubjects.Rows[Convert.ToInt32(e.CommandArgument)].FindControl("DropDownListMySubjectz");
DataSource that populate the gridview
<asp:ObjectDataSource ID="ObjectDataSourceProfileSubjects" runat="server" SelectMethod="GetUserSubjects"
TypeName="ProfileDataAccess">
<SelectParameters>
<asp:ControlParameter ControlID="HiddenFieldUserId" Name="suserId" PropertyName="Value"
Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
我的猜測是,你的GridView的刷新自己在每一個回發,你的數據綁定方法不會被調用。你的代碼在什麼時候嘗試填充你的下拉列表? – MadHenchbot
我有一個LinkButton當我點擊它時,它的命令事件被調用,執行這段代碼。沒有GridView不刷新。我有很多隻在點擊時擊中的突破點。 – user1575229
您的下拉列表是否位於更新面板中?您提到的回傳是完整的回傳嗎? –