下拉列表无法在GridView中正确显示年龄 [英] Drop Down List not displays age correctly in gridview
本文介绍了下拉列表无法在GridView中正确显示年龄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<asp:GridView ID="xmlGrid" runat="server" AutoGenerateColumns="False" BackColor="White"
BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4" Width="336px"
Height="160px" onrowdatabound="xmlGrid_RowDataBound"
onselectedindexchanged="xmlGrid_SelectedIndexChanged">
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="#330099" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<SortedAscendingCellStyle BackColor="#FEFCEB" />
<SortedAscendingHeaderStyle BackColor="#AF0101" />
<SortedDescendingCellStyle BackColor="#F6F0C0" />
<SortedDescendingHeaderStyle BackColor="#7E0000" />
<Columns>
<asp:TemplateField HeaderText="EmployeeID">
<ItemTemplate>
<asp:Label ID="empId" runat="server" Text='<%#Eval("Id")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="EmployeeName" DataField="Name" />
<asp:TemplateField >
<HeaderTemplate>Age</HeaderTemplate>
<ItemTemplate>
<asp:DropDownList ID="empAge" runat="server" Width="100%" DataSource='<%#Eval("age")%>'>
</asp:DropDownList>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="empAge" runat="server" DataSource='<%#Eval("age")%>'>
<asp:ListItem>21</asp:ListItem>
<asp:ListItem>22</asp:ListItem>
<asp:ListItem>23</asp:ListItem>
<asp:ListItem>24</asp:ListItem>
<asp:ListItem>25</asp:ListItem>
<asp:ListItem>26</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Link" ShowEditButton="true" />
</Columns>
</asp:GridView>
DataSet ds = new DataSet();
ds.ReadXml(MapPath(〜/xmlData.xml"));
xmlGrid.DataSource = ds;
xmlGrid.DataBind();
DataSet ds = new DataSet();
ds.ReadXml(MapPath("~/xmlData.xml"));
xmlGrid.DataSource = ds;
xmlGrid.DataBind();
推荐答案
我认为您应该再次检查xmlData.xml数据.
也许.xml文件与您在gridview中的列不匹配.
I think you should check xmlData.xml data again.
maybe the .xml file not match your columns in gridview.
而不是这个
Instead Of This One
<asp:dropdownlist id="empAge" runat="server" width="100%" datatextfield="<%#Eval("age")%>" >
U可以直接使用
U Can Directly Use
<%#Eval("age")%>
这样每个员工的年龄都会负担
So That Age Will Load for Each Employee
这是解决方案...
更改ItemTemplate
Here Is the Solution...
Change In ItemTemplate
DataSource=''<%#Eval("age")%>''
致
To
DataTextField=''<%#Eval("age")%>''
像这样...
Like This...
<itemtemplate>
<asp:dropdownlist id="empAge" runat="server" width="100%"
DataTextField=''<%#Eval("age")%>''>
</itemtemplate>
这篇关于下拉列表无法在GridView中正确显示年龄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文