查询数据集以在gridview中显示值 [英] Query the dataset to show values in gridview
本文介绍了查询数据集以在gridview中显示值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据集并从DB获取推荐值和优先级等值,如果优先级为1,2,3我必须显示YES,如果它是4,5 NO,则将其显示在gridview中。截至目前我是显示YES为1,2,3,4,5如何显示NO,因为我从DB获取值。
I have a dataset and getting values like Recommendation and Priority from DB if priority is 1,2,3 i have to show YES and if it is 4,5 NO, and display it in a gridview.As of now i am displaying YES for 1,2,3,4,5 how to display NO as i am getting the values from DB.
推荐答案
如果您使用ASP.net检查这个链接。
GridView事件处理 [ ^ ]
If you are using ASP.net check this link.
GridView Event Handling[^]
在网格模板中使用eval属性,如下所示。
Use eval property in your grid template as shown below.
<asp:label id="lblPriority" runat="server" text="<%# (Convert.ToInt32( Eval("Priority"))== 4 || Convert.ToInt32( Eval("Priority"))== 5 ? "No" : "Yes") %>" xmlns:asp="#unknown">
</asp:label>
完整代码
1. aspx
full code
1. aspx
<asp:gridview runat="server" id="grid1" autogeneratecolumns="False" xmlns:asp="#unknown">
<columns>
<asp:templatefield headertext="EmployeeID">
<itemtemplate>
<asp:label id="lblID" runat="server" text="<%# Eval("EmployeeID") %> "></asp:label>
</itemtemplate>
</asp:templatefield>
<asp:templatefield headertext="Name">
<itemtemplate>
<asp:label id="lblName" runat="server" text="<%# Eval("Name") %> "></asp:label>
</itemtemplate>
</asp:templatefield>
<asp:templatefield headertext="Priority ">
<itemtemplate>
<asp:label id="lblPriority" runat="server" text="<%# (Convert.ToInt32( Eval("Priority"))== 4 || Convert.ToInt32( Eval("Priority"))== 5 ? "No" : "Yes") %>">
</asp:label>
</itemtemplate>
</asp:templatefield>
</columns>
</asp:gridview>
2.aspx.cs code
2.aspx.cs code
protected void Page_Load(object sender, EventArgs e)
{
var list = new List<employee>
{
new Employee() {EmployeeID = 1, Name = "Peter",Priority=2},
new Employee() {EmployeeID = 2, Name = "Jack",Priority=4},
new Employee() {EmployeeID = 3, Name = "Rich",Priority=1},
};
grid1.DataSource = list;
grid1.DataBind();
}</employee>
这篇关于查询数据集以在gridview中显示值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文