Click here to Skip to main content
15,889,879 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello, Everyone
i am binding a grid. in a template field a label has values coming from database,
i want if value is 0 ar 1 it print reply and if more than 1 it'll show replies.
please help me,
the code is i want to print reply ahead of reply label.
XML
<asp:TemplateField ItemStyle-Width="100px">
               <ItemTemplate>
               <asp:Label ID="lblUserName" runat="server" Text='<%# Bind("UserName") %>'></asp:Label>
               <br/>
               <asp:Label ID="lblNoofReply" runat="server" Text='<%# Bind("NoOfReply") %>'></asp:Label>

               </ItemTemplate>
               </asp:TemplateField>
Posted

use Grid View
OnRowDataBound event

and write code for that event on code behind.


Quote:
Before the GridView control can be rendered, each row in the control must be bound to a record in the data source. The RowDataBound event is raised when a data row (represented by a GridViewRow object) is bound to data in the GridView control. This enables you to provide an event-handling method that performs a custom routine, such as modifying the values of the data bound to the row, whenever this event occurs.

A GridViewRowEventArgs object is passed to the event-handling method, which enables you to access the properties of the row being bound. To access a specific cell in the row, use the Cells property of the GridViewRow object contained in the Row property of the GridViewRowEventArgs object. You can determine which row type (header row, data row, and so on) is being bound by using the RowType property.
 
Share this answer
 
Here you can replace the reply label with this when and try:

ASP.NET
<asp:label id="lblNoofReply" runat="server">
Text='<%# Convert.ToInt32(Bind("NoOfReply")) > 1 ? "Replies" : "Reply"%>'>
</asp:label>


Hope it helps

Azee...
 
Share this answer
 
v2
Comments
Mohd Arif Khan 1-Oct-13 7:17am    
Thanq :)
Azee 1-Oct-13 7:20am    
Whoever down voted the solution, would you care providing a reason for that?
Mohd Arif Khan 1-Oct-13 7:29am    
i have not tried conditional operators i was checking on rowbound event.

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