Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 回发后丢失detailsview dropdownlist值_C#_Asp.net - Fatal编程技术网

C# 回发后丢失detailsview dropdownlist值

C# 回发后丢失detailsview dropdownlist值,c#,asp.net,C#,Asp.net,我在detailsview中使用了dropdownlist,它可以很好地填充,但是当我插入时会有回发,所以我试图再次绑定DDL,但是这些值不知为什么丢失了 我的aspx: <asp:UpdatePanel ID="InsertPanel" runat="server" UpdateMode="Conditional" > <ContentTemplate> <asp:Table ID="Table1" runat="server" CellS

我在detailsview中使用了dropdownlist,它可以很好地填充,但是当我插入时会有回发,所以我试图再次绑定DDL,但是这些值不知为什么丢失了

我的aspx:

<asp:UpdatePanel ID="InsertPanel" runat="server" UpdateMode="Conditional" >
    <ContentTemplate>
        <asp:Table ID="Table1" runat="server" CellSpacing="0" CellPadding="0">
            <asp:TableHeaderRow SkinID="tableheaderrowSkin">
            </asp:TableHeaderRow>
            <asp:TableRow>
                <asp:TableCell BackColor="DarkGray" BorderColor="DarkGray" BorderWidth="1" Width="300">
                    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="nFuturesId"
                            DataSourceID="FutureCommodityODS" DefaultMode="Insert" OnItemInserting="DetailsView1_ItemInserting"
                            SkinID="detailsviewSkin" OnItemInserted="DetailsView1_ItemInserted" EnableModelValidation="True">

                            <BrummerComp:SortableDropDownList ID="DropDownListFuturesInsert" runat="server"  SkinID="BCdropdownlistSkin">
                            </BrummerComp:SortableDropDownList>  
                    </asp:DetailsView>
                </asp:TableCell>
            </asp:TableRow>
        </asp:Table>
    </ContentTemplate>
</asp:UpdatePanel>
BindDropDownList:

private void BindDropDownList()
{
    var paperFutureList = (List<PaperFutures>)DataManager.GetPaperFutures();
    var ddl = (DropDownList)DetailsView1.FindControl("DropDownListFuturesInsert");
    ddl.DataSource = paperFutureList;
    ddl.DataValueField = "nFuturesID";
    ddl.DataTextField = "ShortNameAndFutureNameAndFutureId";
    ddl.DataBind();
}
private void BindDropDownList()
{
var paperFutureList=(List)DataManager.GetPaperFutures();
var ddl=(DropDownList)DetailsView1.FindControl(“DropDownListFuturesInsert”);
ddl.DataSource=paperFutureList;
ddl.DataValueField=“nFuturesID”;
ddl.DataTextField=“ShortNameAndFutureNameAndFutureId”;
ddl.DataBind();
}
问题是,当我在我的Details视图中插入时,DDL将丢失其值。我已经尝试了对detailsview进行数据绑定,但是根本不会加载这些值

BindDropDownList方法在首次加载页面时效果良好。还试着把methodcall放在外面!我返回到总是填充它,但这也不起作用


我已经检查了GetPaperFutures(),每次都运行良好,所以问题出在其他地方,但我找不到问题所在。

我也遇到过类似的问题。最终,我找到了解决办法

只需在Page_PreRender事件中调用BindDropDownList()。


它成功地工作了

清除数据源并再次绑定!已尝试在页面加载中使用ddl.Items.Clear,但仍然无法在页面加载中使用!装订时!ddl.DataSource=null;comboBox1.DataSource=paperFutureList;尝试在ddl.DataSource=paperFutureList之前在BindDropDownList中清除它,但仍不工作。请确保页面和DropDownList的EnableViewState等于true
private void BindDropDownList()
{
    var paperFutureList = (List<PaperFutures>)DataManager.GetPaperFutures();
    var ddl = (DropDownList)DetailsView1.FindControl("DropDownListFuturesInsert");
    ddl.DataSource = paperFutureList;
    ddl.DataValueField = "nFuturesID";
    ddl.DataTextField = "ShortNameAndFutureNameAndFutureId";
    ddl.DataBind();
}