我有一个下拉列表
<asp:DropDownList ID="DropDownListMySubjectz" runat="server">
</asp:DropDownList>
我尝试在 C# 的 CodeBehind 中填充它。
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>