GridView位于下拉列表上方。但是,我想要反过来。下载列表以编程方式添加

时间:2016-04-25 15:19:35

标签: asp.net vb.net

enter image description here动态创建下拉列表项会自动将项目添加到页面底部。我有一个GridView和下拉列表项。希望下拉项目显示在gridView

上方
$outerHash{"Master1"} = {}; %{$outerHash{"Master1"}} = %innerHash1;

上面的HTML代码:

VB.net代码

<body>
        <form id="form1" runat="server">
        <div>

        </div>

            &nbsp;<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" Height="273px" Width="450px">
                  <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                  <EditRowStyle BackColor="#999999" />
                  <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                  <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                  <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                  <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                  <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                  <SortedAscendingCellStyle BackColor="#E9E7E2" />
                  <SortedAscendingHeaderStyle BackColor="#506C8C" />
                  <SortedDescendingCellStyle BackColor="#FFFDF8" />
                  <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                  </asp:GridView>
     &nbsp;&nbsp;<br />
            &nbsp;
            <div>
                <asp:Button ID="InputPageSubmitButton" runat="server" Text="Submit" Width="149px" />
            </div>
        </form>
    </body>

2 个答案:

答案 0 :(得分:2)

您可以在GridView上方的表格中添加一系列DropDownLists,并定义一个类样式以确保所有列具有相同的宽度:

<form id="form1" runat="server">
    <asp:Panel runat="server" Width="3000">
        <asp:Table ID="tblLists" runat="server" CssClass="fixedColWidth" ...>
            <asp:TableRow ID="trLists" runat="server" ></asp:TableRow>
        </asp:Table>
        <asp:GridView ID="GridView1" runat="server" CssClass="fixedColWidth" ... >
        ...
        </asp:GridView>
    </asp:Panel>

使用此样式定义:

.fixedColWidth td
{
    width: 150px;
}

然后使用以下代码将DropDownLists添加到表行:

Private Sub Page_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
    trLists.Cells.Clear()
    For i As Integer = 0 To GridView1.Columns.Count - 1
        Dim dd1 As New DropDownList()
        dd1.ID = "dd1" + i.ToString()
        dd1.Width = Unit.Pixel(140)
        dd1.Items.Add("Borough")
        Dim cell As New TableCell()
        cell.Controls.Add(dd1)
        trLists.Cells.Add(cell)
    Next
End Sub

在此示例中,列宽设置为150像素。您可以修改类样式和代码以满足您的需求。

答案 1 :(得分:1)

form1.Controls.AddAt(0,dd1)

尝试AddAt方法。