使用c#在asp.net的gridview中添加下拉列表 [英] adding dropdownlist in gridview in asp.net using c#
本文介绍了使用c#在asp.net的gridview中添加下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用C#在asp.net的gridview中添加下拉列表。
我的源页面代码如下;
< asp:GridView ID = gvfaculty runat = server BackColor = LightGoldenrodYellow BorderColor = Tan
BorderWidth = 1px CellPadding = 2 ForeColor = 黑色 GridLines = 无 高度 = 124px
宽度 = 91px AutoGenerateEditButton = < span class =code-keyword> True AutoGenerateColumns = 错误 >
< alternatingrow style backcolor = PaleGoldenrod / >
< ; 页脚 样式 < span class =code-attribute> backcolor = Tan / >
< HeaderStyle BackColor = Tan Font-Bold = True / >
< pager style backcolor = PaleGoldenrod forecolor = DarkSlateBlue horizontalalign = 中心 / >
< SelectedRowStyle BackColor = DarkSlateBlue ForeColor = GhostWhite / >
< sortedascendingcell style backcolor = #FAFAE7 / >
< 跨度> <跨度class =code-leadattribute> sortedascendingheader style backcolor = #DAC09E / >
< ; sorteddescendingcell style < span class =code-attribute> backcolor = #E1DB9C / >
< sorteddescendingheader style backcolor = #C2A47B / >
< 列 > ;
< asp:TemplateField HeaderText = 教师姓名 >
< asp:TemplateField HeaderText 跨度> = 1 >
< itemtemplate >
< asp:DropDownList < span class =code-attribute> id = Rating1 runat = server >
< asp:ListItem Value = 4 > 优秀
< asp:ListItem 值 = 1 > 好
< asp:ListItem 值 = 2 > Fair
< asp:ListItem < span class =code-attribute> 值 = 3 > P. oor
< / itemtemplate >
< asp:TemplateField HeaderText = 2 >
< itemtemplate >
< asp:DropDownList id = Rating2 runat = 服务器 >
< asp:ListItem 值 = 4 > 优秀
< asp:ListItem 值 = 1 > 好
< asp:ListItem 值 = 2 > Fair
< asp:ListItem 值 = 3 < span class =code-keyword>> 差
< / itemtemplate >
< asp:TemplateField HeaderText = 3 >
< itemtemplate >
< asp:DropDownList id = Rating3 runat = 服务器 >
< asp:ListItem 值 = 4 > 优秀
< asp:ListItem 值 = 1 > 好
< asp:ListItem 值 = 2 > Fair
< asp:ListItem 值 = 3 > 差
< / itemtemplate >
< asp:TemplateField HeaderText = 4 >
< itemtemplate >
< asp:DropDownList id = Rating4 < span class =code-attribute> runat = 服务器跨度> <跨度class =code-keyword>>
< asp:ListItem 值 = 4 > 优秀
< < span class =code-leadattribute> asp:ListItem 值 = 1 > 好
< asp:ListItem 值 = 2 > 公平
< asp:ListItem 值 = 3 > ; 差
< / itemtemplate >
< asp:TemplateField HeaderText = 5 >
< itemtemplate >
< asp:DropDownList id = Rating5 runat = 服务器 >
< asp:ListItem 值 = 4 > 优秀
< asp:ListItem 值 = 1 > 好
< asp:ListItem 值 = 2 > Fair
< asp:ListItem 值 = 3 > 差
< / itemtemplate >
< / colu mns >
在运行模式下输出如下;
学院名称1 2 3 4 5
Ram dropdownlist1 dropdownlist2 dropdownlist3 dropdownlist4 dropdownlist5
i想要为gridview中的下一行添加下拉列表。
i想要输出如下;
学院名称1 2 3 4 5
Ram dropdownlist1 dropdownlist2 dropdownlist3 dropdownlist4 dropdownlist5
Sam dropdownlist1 dropdownlist2 dropdownlist3 dropdownlist4 dropdownlist5
为什么我在asp.net中使用c#。
解决方案
DataSource
包含两行,则 GridView
和其他所有将显示两行也会出现行中的DropDownLists
。
这意味着 GridView
行是只是 DataSource
中存在的行的副本。
您可以在这样的itemtemplate中设置下拉菜单
< asp:gridview id = gv1 runat = server xmlns: asp = #unknown >
< 列 >
< asp:templatefield headertext = 第1列 >
< itemtemplate >
< < span class =code-leadattribute> asp:dropdownlist id = ddl1 runat = 服务器 >
< asp:listitem value = 4 text = 优秀 > < / asp:listitem >
< asp:listitem value = 1 text = 好 > < / asp:listitem >
< asp:listitem 值 = 2 text = 公平 < span class =code-keyword>> < / asp:listitem < span class =code-keyword>>
< asp:listitem value = 3 text = 差 > < / asp:listitem >
< / asp:dropdownlist >
< / itemtemplate >
< / asp:templatefield >
< asp:templatefield < span class =code-attribute> headertext = 第2列 >
< itemtemplate >
< asp:dropdownlist id = ddl2 runat = 服务器 >
< asp:listitem value = 4 text = 优秀 < span class =code-keyword>> < / asp:listitem < span class =code-keyword>>
< asp:listitem value = 1 text = 好 > < / asp:listitem >
< asp:listitem value = 2 text = < span class =code-keyword>合格 > < / asp:listitem >
< asp:listitem value = 3 文本 = 差 > < / asp:listitem >
< / asp:dropdownlist < span class =code-keyword>>
< / itemtemplate >
< / asp: templatefield >
< / columns >
< / asp:gridview >
Adding dropdownlist in gridview in asp.net using C#.
My source page code as follows;
<asp:GridView ID="gvfaculty" runat="server" BackColor="LightGoldenrodYellow" BorderColor="Tan"
BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None" Height="124px"
Width="91px" AutoGenerateEditButton="True" AutoGenerateColumns="False">
<alternatingrowstyle backcolor="PaleGoldenrod" />
<footerstyle backcolor="Tan" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<pagerstyle backcolor="PaleGoldenrod" forecolor="DarkSlateBlue" horizontalalign="Center" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<sortedascendingcellstyle backcolor="#FAFAE7" />
<sortedascendingheaderstyle backcolor="#DAC09E" />
<sorteddescendingcellstyle backcolor="#E1DB9C" />
<sorteddescendingheaderstyle backcolor="#C2A47B" />
<columns>
<asp:TemplateField HeaderText ="Faculty Name">
<asp:TemplateField HeaderText = "1">
<itemtemplate>
<asp:DropDownList id="Rating1" runat="server">
<asp:ListItem Value="4">Excellent
<asp:ListItem Value="1">Good
<asp:ListItem Value="2">Fair
<asp:ListItem Value="3">Poor
</itemtemplate>
<asp:TemplateField HeaderText = "2">
<itemtemplate>
<asp:DropDownList id="Rating2" runat="server">
<asp:ListItem Value="4">Excellent
<asp:ListItem Value="1">Good
<asp:ListItem Value="2">Fair
<asp:ListItem Value="3">Poor
</itemtemplate>
<asp:TemplateField HeaderText = "3">
<itemtemplate>
<asp:DropDownList id="Rating3" runat="server">
<asp:ListItem Value="4">Excellent
<asp:ListItem Value="1">Good
<asp:ListItem Value="2">Fair
<asp:ListItem Value="3">Poor
</itemtemplate>
<asp:TemplateField HeaderText = "4">
<itemtemplate>
<asp:DropDownList id="Rating4" runat="server">
<asp:ListItem Value="4">Excellent
<asp:ListItem Value="1">Good
<asp:ListItem Value="2">Fair
<asp:ListItem Value="3">Poor
</itemtemplate>
<asp:TemplateField HeaderText = "5">
<itemtemplate>
<asp:DropDownList id="Rating5" runat="server">
<asp:ListItem Value="4">Excellent
<asp:ListItem Value="1">Good
<asp:ListItem Value="2">Fair
<asp:ListItem Value="3">Poor
</itemtemplate>
</columns>
In run mode output as follows;
Faculty Name 1 2 3 4 5
Ram dropdownlist1 dropdownlist2 dropdownlist3 dropdownlist4 dropdownlist5
i want to add the dropdownlist for next row in gridview.
i want the output as follows;
Faculty Name 1 2 3 4 5
Ram dropdownlist1 dropdownlist2 dropdownlist3 dropdownlist4 dropdownlist5
Sam dropdownlist1 dropdownlist2 dropdownlist3 dropdownlist4 dropdownlist5
for that how can i do in asp.net using c#.
解决方案
If yourDataSource
contains two rows, then two rows will show onGridView
and all otherDropDownLists
in the Row will also appear.
That meansGridView
rows are just a replica of the rows present in yourDataSource
.
You can set your dropdowns in an itemtemplate like this
<asp:gridview id="gv1" runat="server" xmlns:asp="#unknown"> <columns> <asp:templatefield headertext="Column 1"> <itemtemplate> <asp:dropdownlist id="ddl1" runat="server"> <asp:listitem value="4" text="Excellent"></asp:listitem> <asp:listitem value="1" text="Good"></asp:listitem> <asp:listitem value="2" text="Fair"></asp:listitem> <asp:listitem value="3" text="Poor"></asp:listitem> </asp:dropdownlist> </itemtemplate> </asp:templatefield> <asp:templatefield headertext="Column 2"> <itemtemplate> <asp:dropdownlist id="ddl2" runat="server"> <asp:listitem value="4" text="Excellent"></asp:listitem> <asp:listitem value="1" text="Good"></asp:listitem> <asp:listitem value="2" text="Fair"></asp:listitem> <asp:listitem value="3" text="Poor"></asp:listitem> </asp:dropdownlist> </itemtemplate> </asp:templatefield> </columns> </asp:gridview>
这篇关于使用c#在asp.net的gridview中添加下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文