C#.net中Gridview内的下拉列表 [英] Dropdown list inside the Gridview in C#.net
本文介绍了C#.net中Gridview内的下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我在网格中有下拉列表,而在网格中编辑行时,我需要在下拉列表中显示先前的值.
请帮忙 .
谢谢
Mohan
Hi All,
I have dropdown list inside the grid, while edit the row in grid i need to display the previous value in the drop down list .
Please help .
Thanks
Mohan
推荐答案
<asp:GridView ID="GrdSample" CssClass="task-table" runat="server" Width="485px" AutoGenerateColumns="False"
AllowPaging="True" PageSize="12">
<Columns>
<asp:BoundField DataField="ColName" HeaderText="Name" />
<asp:BoundField DataField="ColAge" HeaderText="Age" />
<asp:TemplateField HeaderText="Delete" >
<ItemTemplate >
<asp:DropDownList ID="ddlSubject" AutoPostBack="True" onselectedindexchanged="ddlSubject_SelectedIndexChanged" Width = "100px" runat="server"> </asp:DropDownList>
</ItemTemplate>
<FooterStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Top" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</asp:GridView>
C#代码:
C# code:
DropDownList ddlSubject = (DropDownList)GrdSample.Rows[iCount-1].FindControl("ddlSubject");
然后您可以获得下拉列表的任何值并显示在任何位置,您可以在itemtemplate列中添加一个标签并将其显示.
and then you can get any value of dropdown list and display any where , you can take a label in itemtemplate column and display it .
朋友,
使用像这样的隐藏控件
hi friend,
use hidden controls like this
<asp:Label ID="something" style="display:none" Text="" runat="server"></asp:Label>
然后将您以前的dropdownlist值存储在LblPrevious中.
例如:
then store your previous dropdownlist value in LblPrevious.
for examples:
LblPrevious.Text="your Dropdownlist value";
问候
sarva
regards
sarva
可能会帮助您...
aspdontnet [ http://www.aspsnippets. com/Articles/Populate-DropDownList-Selected-in-EditItemTemplate-of-GridView-in-ASPNet.aspx [
Hi,
May help you...
aspdontnet[^]
http://www.aspsnippets.com/Articles/Populate-DropDownList-with-Selected-Value-in-EditItemTemplate-of-GridView-in-ASPNet.aspx[^]
这篇关于C#.net中Gridview内的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文