【发布时间】:2018-07-06 10:36:02
【问题描述】:
我在数据库中有一个存储整数值的列(4、6、8...)。 这些整数值应该是 TextBox 的最大允许长度,这是Table。
这是来自 c# 的代码,我暂时在其中传递了特征名称和整数(数据库中文本框的最大位置数)。
protected void ddlBC_SelectedIndexChanged(object sender, EventArgs e)
{
//ddlKar.Items.Clear();
LogicTableAdapters.getLvLOneIntegerTableAdapter getKar = new LogicTableAdapters.getLvLOneIntegerTableAdapter();
DataTable dtKar = getKar.getLvLOneInteger(ddlBC.SelectedValue);
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[2]{ new DataColumn("CharacteristicName", typeof(string)) new DataColumn("MaxNoPlaces", typeof(string))});
foreach (DataRow dr in dtKar.Rows)
{
dt.Rows.Add(dr["CharacteristicName"].ToString(), dr["MaxNoPlaces"].ToString());
}
gvKarakteristike.DataSource = dt;
gvKarakteristike.DataBind();
}
这是asp部分:
<asp:GridView ID="gvKarakteristike" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" DataKeyNames="LevelID" OnRowDataBound="gvKarakteristike_RowDataBound">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Characteristics">
<ItemTemplate>
<asp:Label ID="Characteristics" runat="server" Width="150px" Height="30px" Font-Names="Georgia" margin-Left="100px" Text='<%# Bind("CharacteristicName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:DropDownList ID="ddlOpis" AppendDataBoundItems="true" Width="142px" Height="35px" Font-Names="Georgia" margin-Left="100px" runat="server">
<asp:ListItem Text="" Value="" />
</asp:DropDownList>
<asp:TextBox ID="txtBoxOpis" runat="server" Width="130px" Height="28px" Font-Names="Georgia" margin-Left="100px" Text='<%# Bind("MaxNoPlaces") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
我需要直接从数据库中动态地进行此操作,因为数据库会随着时间的推移而增长,文本框的数量也会随之增长。
我可以用 jquery 或 asp 来做这件事吗? 提前致谢!
【问题讨论】:
标签: c# jquery asp.net webforms