动态创建下拉列表项会自动将项目添加到页面底部。我有一个GridView和下拉列表项。希望下拉项目显示在gridView
$outerHash{"Master1"} = {}; %{$outerHash{"Master1"}} = %innerHash1;
上面的HTML代码:
VB.net代码
<body>
<form id="form1" runat="server">
<div>
</div>
<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>
<br />
<div>
<asp:Button ID="InputPageSubmitButton" runat="server" Text="Submit" Width="149px" />
</div>
</form>
</body>
答案 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
方法。