带有下拉列表的继承代码,用于填充某些GridView。在下拉列表中进行选择时,选择不会保留,它会跳回到第一条记录。经常提到的修复方法是在Page_Load事件中添加!Page.IsPostBack,但是这样做不能解决问题。
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="true"
DataSourceID="SqlDataSource2" DataTextField="FullAddress"
DataValueField="UniqueRecordID" Width="445px" Height="20px"
style="margin-left: 0px" TabIndex="8" AppendDataBoundItems="true"
OnSelectedIndexChanged="resetGridsAndLabel">
</asp:DropDownList>
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DropDownList2.DataSource = sqlDataSource2;
DropDownList2.DataBind();
}