亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

根據列值生成 TextBox 或 DropDownList

根據列值生成 TextBox 或 DropDownList

C#
慕的地8271018 2022-01-15 19:23:04
我的表中有一個名為 ColumnType 的列。ColumnType 應該具有基于列 TypeID 的值的 TextBox 或 DropDownlist。如果 TypeID 列中的值為 0、2、3,則應顯示空文本框,如果值為 1,則應在頁面上顯示空 DDL。這是從代碼生成表格時的樣子: https ://jsfiddle.net/769825dz/7/這是 C# 代碼,我只是從過程中獲取值并將其發送到逐列顯示到 aspx:LogicTableAdapters.getCharacteristicTableAdapter getObChar = new LogicTableAdapters.getCharacteristicTableAdapter();DataTable dtObChar = getObChar.getCharacteristicTableAdapter(Convert.ToInt32("1"));DataTable dtCh = new DataTable();dtCh.Columns.AddRange(new DataColumn[4]{ new DataColumn("CharacteristicID", typeof(string)), new DataColumn("CharacteristicName", typeof(string)), new DataColumn("ColumnType", typeof(string)), new DataColumn("TypeID", typeof(int)),});foreach (DataRow dr in dtObChar.Rows){    dtCh.Rows.Add(dr["CharacteristicID"].ToString(), dr["CharacteristicName"].ToString(), dr["ColumnType"] == DBNull.Value ? null : dr["TypeID"].ToString());}gvObjCharacteristic.DataSource = dtCh;gvObjCharacteristic.DataBind();這是從過程中生成 gridview 的 aspx 部分: <asp:GridView ID="gvObjCharacteristic" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False">    <AlternatingRowStyle BackColor="White" />    <Columns>        <asp:TemplateField HeaderText="CharacteristicID">            <ItemTemplate>                <asp:Label ID="CharacteristicID" runat="server" class="ObjekatID" Width="118px" Height="26px" Style="text-align: center" Font-Names="Georgia" margin-Left="100px" Text='<%# Bind("CharacteristicID") %>'></asp:Label>            </ItemTemplate>        </asp:TemplateField>        <asp:TemplateField HeaderText="CharacteristicName">            <ItemTemplate>                <asp:Label ID="CharacteristicName" runat="server" Width="118px" Height="26px" Style="text-align: center" Font-Names="Georgia" margin-Left="100px" Text='<%# Bind("CharacteristicName") %>'></asp:Label>            </ItemTemplate>        </asp:TemplateField>    </Columns></asp:GridView>我想我在 c# 部分需要一些代碼。有人可以幫我嗎?
查看完整描述

1 回答

?
神不在的星期二

TA貢獻1963條經驗 獲得超6個贊

您可以Visible根據 Column 值設置 TextBox 或 DropDownList 的屬性。


<asp:TemplateField>

    <ItemTemplate>


        <asp:TextBox ID="TextBox1" runat="server" Visible='<%# Convert.ToInt32(Eval("TypeID")) != 1 %>'></asp:TextBox>


        <asp:DropDownList ID="DropDownList1" runat="server" Visible='<%# Convert.ToInt32(Eval("TypeID")) == 1 %>'>

            <asp:ListItem Text="Value 1" Value="1"></asp:ListItem>

            <asp:ListItem Text="Value 2" Value="2"></asp:ListItem>

            <asp:ListItem Text="Value 3" Value="3"></asp:ListItem>

        </asp:DropDownList>


    </ItemTemplate>

</asp:TemplateField>

而且你不需要創建一個新的DataTable,你可以這樣做


gvObjCharacteristic.DataSource = getObChar.getCharacteristicTableAdapter(Convert.ToInt32("1"));;



查看完整回答
反對 回復 2022-01-15
  • 1 回答
  • 0 關注
  • 126 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號