0

ドロップダウンリスト列を持つグリッドビューがあり、ページング機能を有効にしました。問題は、次のページに移動するたびに、前のページのドロップダウンリストの選択値がデフォルト値に戻ることです。

コードを でラップしようとしましたがif(!ispostback)、利用可能な最初のページのみ他のページが消えます

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            List<CPDEmployee> employeelist = (List<CPDEmployee>)Cache["EmployeeList"];

            unverifiedlist.DataSource = employeelist;
            unverifiedlist.AllowPaging = true;
            unverifiedlist.PageSize = 10;
            unverifiedlist.DataBind();
        }
    }
protected void PageSelect_SelectedIndexChanged(object sender, EventArgs e)
{
    int page = int.Parse(PageSelect.SelectedItem.Text);
    unverifiedlist.PageIndex = page;
    DataBind();
}





 <asp:GridView ID="unverifiedlist" runat="server" AutoGenerateColumns="false" AllowSorting="true" AllowPaging="true" ViewStateMode="Enabled">
                        <Columns><asp:TemplateField HeaderText="Options" >
                                <ItemTemplate>
                                    <asp:DropDownList ID="options" runat="server" AutoPostBack="true">
                                        <asp:ListItem Value="1">Verified</asp:ListItem>
                                        <asp:ListItem Value="0">Rejected</asp:ListItem>
                                    </asp:DropDownList>
                                </ItemTemplate>
                             </asp:TemplateField>
                    </Columns>
                    <PagerSettings Visible="false"/>            
        </asp:GridView>
<asp:DropDownList ID="PageSelect" runat="server" AutoPostBack="true" OnSelectedIndexChanged="PageSelect_SelectedIndexChanged"></asp:DropDownList>

誰もそれを修正する方法を知っていますか、どこに置くべきですか ispostback? ありがとう

4

1 に答える 1

1

OnRowDataBound を処理し、適切な要素をプログラムで設定する必要があります。例:

<asp:GridView ID="unverifiedlist" runat="server" 
   OnRowDataBound="unverifiedlist_RowDataBound" AutoGenerateColumns="false" 
    AllowSorting="true" AllowPaging="true" ViewStateMode="Enabled">

そして、次のようなものを実装します:

protected void unverifiedlist_RowDataBound(Object sender, GridViewRowEventArgs e)
{
  if(e.Row.RowType == DataControlRowType.DataRow)
  {
     ((DropDownList)e.Row.FindControl("options")).SelectedValue=((CPDEmployee)e.Row.DataItem).Unverified;

  }
}

明らかに、ビジネス オブジェクトに Unverified というプロパティがあると仮定します。適切なものを使用する必要があります。これはほんの一例です。

アップデート:

グリッド内のドロップダウンは自動ポスト バックであるため、OnSelectedIndexChanged のイベント ハンドラーをグリッド内のドロップダウン リストに追加します。何かのようなもの:

<asp:DropDownList ID="options" runat="server" AutoPostBack="true" OnSelectedIndexChanged="options_SelectedIndexChanged">
  <asp:ListItem Value="1">Verified</asp:ListItem>
  <asp:ListItem Value="0">Rejected</asp:ListItem>
</asp:DropDownList>

その後

protected void options_SelectedIndexChanged(object sender, EventArgs e)
{ 
    string selecteValue = ((DropDownList)sender).SelectedValue;
    //Now persist this value in the appropriate business object  
    //this is the difficult part because you don't know for which row in the gridview
    //you are changing this selection. You'll need to devise a way to pass an extra 
    //value (an Employee ID, I would imagine) that would allow you to grab the 
    // record from the List<CDPEmployee> and change the property to the new selection.
}
于 2012-05-01T18:15:52.603 に答える