Click here to Skip to main content
15,920,217 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

If you are using ASP.net check this link.

GridView Event Handling[^]
 
Share this answer
 
Use eval property in your grid template as shown below.


C#
<asp:label id="lblPriority" runat="server" text="<%# (Convert.ToInt32( Eval("Priority"))== 4 || Convert.ToInt32( Eval("Priority"))== 5  ? "No" : "Yes") %>" xmlns:asp="#unknown">
                            </asp:label>



full code

1. aspx

C#
<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

C#
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>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900