网格视图中的 DropDownList 不起作用

Posted

技术标签:

【中文标题】网格视图中的 DropDownList 不起作用【英文标题】:DropDownList in grid view did not working 【发布时间】:2013-05-30 08:22:19 【问题描述】:

aspx代码:

  <asp:GridView ID="PaperReviewing" runat="server" CellPadding="4" EmptyDataText="There is no Submission"DataKeyNames="PaperId" RowStyle-Wrap="true"  OnRowDataBound="PaperReviewing_RowDataBound">

              <Columns>
             <asp:TemplateField HeaderText="Action" ControlStyle-Width="200px" >
                <ItemTemplate>

                    <br />
                    <asp:HyperLink ID="HyperLink3" Target="_blank" ForeColor="Black" onclick="javascript:window.open(this.href,'ManuScript Details','resizable=no,scroll bars=yes,status=no,toolbar=yes,height=500,width=700,left=50,top=40');return true;"
                    NavigateUrl='<%# String.Format("~/EditorsInChief/DownloadSubFileList.aspx?ID=0", Eval("PaperId")) %>' runat="server">File Inventory</asp:HyperLink>

                  <br /><asp:HyperLink ID="HyperLink4" Target="_blank" ForeColor="Black" onclick="javascript:window.open(this.href,'ManuScript Details','resizable=no,scroll bars=yes,status=no,toolbar=yes,height=500,width=700,left=50,top=40');return true;"
                  NavigateUrl='<%# String.Format("~/EditorsInChief/SelectReviewer.aspx?ID=0", Eval("PaperId")) %>' runat="server">Select Another Reviewer</asp:HyperLink>

                    <br />
                                   </ItemTemplate>

        </asp:TemplateField>
        <asp:BoundField DataField="PaperId" HeaderText="PaperId" InsertVisible="False" 
            ReadOnly="True" SortExpression="PaperId" Visible="False" />
        <asp:BoundField DataField="ManuScriptId" HeaderText="ManuScript Number" 
            SortExpression="ManuScriptId" />
        <asp:BoundField DataField="Type" HeaderText="Article Type" SortExpression="Type" />
           <asp:TemplateField HeaderText="Article Title" HeaderStyle-Wrap="true"  ItemStyle-Wrap="true" ItemStyle-HorizontalAlign="Left" SortExpression="PaperTitle" ControlStyle-Width="200px">

                 <ItemTemplate>
                     <asp:Label ID="Label4" runat="server" Text='<%# Bind("PaperTitle") %>'></asp:Label>
                 </ItemTemplate>
             </asp:TemplateField>
 <asp:BoundField DataField="ReviewerName" HeaderText="Reviewer Name" SortExpression="ReviewerName" />
        <asp:BoundField DataField="Status" HeaderText="Current Status" 
            SortExpression="Status" />
            <asp:BoundField DataField="CreatedDate" HeaderText="Intital Date Submission" SortExpression="CreatedDate" />                
            <asp:BoundField DataField="DateReviewInvited" HeaderText="Date Review Invited" 
                                    SortExpression="DateReviewInvited" />
                                           <asp:BoundField DataField="DateReviewDue" HeaderText="Date Review Due" 
                                    SortExpression="DateReviewDue" />
             <asp:TemplateField HeaderText="EIC Decision">
                 <ItemTemplate>
                     <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
                         onselectedindexchanged="DropDownList1_SelectedIndexChanged">
                     <asp:ListItem Selected="True" Text="Choose Option"></asp:ListItem>
                     <asp:ListItem Text="Accept" Value="Accept"></asp:ListItem>
                     <asp:ListItem Text="Reject" Value="Reject"></asp:ListItem>
                     <asp:ListItem Text="Minor Revision" Value="MinorRevision"></asp:ListItem>
                     <asp:ListItem Text="Major Revision" Value="MajorRevision"></asp:ListItem>
                     </asp:DropDownList>
                 </ItemTemplate>
             </asp:TemplateField>
    </Columns>
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" BorderStyle="Double" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <EditRowStyle BackColor="#2461BF" />
    <AlternatingRowStyle BackColor="White"  />
</asp:GridView>

C# 代码:

protected void DropDownList1_SelectedIndexChanged(对象发送者,EventArgs e) DropDownList DropDownList1 = (DropDownList)sender; GridViewRow grdrDropDownRow = ((GridViewRow)DropDownList1.Parent.Parent); protected void PaperReviewing_RowDataBound(对象发送者,GridViewRowEventArgs e) if (e.Row.RowType == DataControlRowType.DataRow) DropDownList ddl = e.Row.FindControl("DropDownList1") as DropDownList; 如果(ddl!= null) ddl.SelectedIndexChanged += new EventHandler(DropDownList1_SelectedIndexChanged);

下拉 selectedindexchanged 事件不会触发。我正在尝试在运行时更改我的下拉值,在我的数据库值中获取更新。

【问题讨论】:

【参考方案1】:

PaperReviewing_RowDataBound 中删除添加代码的事件处理程序,因为您已经从标记中附加了它

在你的页面加载

protected void Page_Load(object sender, EventArgs e)

  if(!Page.IsPostBack)
  
    DataBindGrid();
  

【讨论】:

以上是关于网格视图中的 DropDownList 不起作用的主要内容,如果未能解决你的问题,请参考以下文章

从另一个视图重新绑定剑道网格到以前的搜索条件的正确方法是啥(后退按钮不起作用)

WP媒体库网格视图不显示

片段内的网格适配器不起作用

在 Extjs 网格视图中隐藏行不起作用

为啥嵌套网格中的星号大小不起作用?

Ext JS 4.1:网格列中的渲染器参数不起作用