我想检查动态生成的值并根据它打印消息 [英] i want to check a dynamically generated value and print msg according to it

查看:61
本文介绍了我想检查动态生成的值并根据它打印消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,每个人

我绑定一个网格。在模板字段中,标签具有来自数据库的值,

i如果值为0则需要打印回复,如果超过1则显示回复。

please帮助我,

代码是我想在回复标签前打印回复。

  <   asp:TemplateField     ItemStyle-Width   =  100px >  
< ItemTemplate >
< asp:Label ID = lblUserName runat = 服务器 文本 =' <% #Bind( UserName%> ' > < / asp:标签 >
< br / >
< asp:Label ID = lblNoofReply runat = server 文本 =' <% #Bind( NoOfReply%> ' > < / asp:Label >

< / ItemTemplate >
< / asp:TemplateField >

解决方案

使用网格视图

OnRowDataBound事件



并为该事件编写代码代码背后。





引用:

在可以呈现GridView控件之前,控件中的每一行都必须绑定到数据源中的记录。当数据行(由GridViewRow对象表示)绑定到GridView控件中的数据时,将引发RowDataBound事件。这使您能够提供执行自定义例程的事件处理方法,例如在发生此事件时修改绑定到行的数据的值。



GridViewRowEventArgs对象被传递给事件处理方法,该方法使您可以访问被绑定行的属性。要访问行中的特定单元格,请使用GridViewRowEventArgs对象的Row属性中包含的GridViewRow对象的Cells属性。您可以使用RowType属性确定要绑定的行类型(标题行,数据行等)。


在此您可以使用此替换回复标签何时尝试:



 <   asp:label     id   =  lblNoofReply    runat   = 服务器 >  
Text ='<%#Convert.ToInt32(Bind( NoOfReply))> 1 回复 回复%GT;'>
< / asp:label >





希望有所帮助



Azee ......


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.

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

解决方案

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.


Here you can replace the reply label with this when and try:

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



Hope it helps

Azee...


这篇关于我想检查动态生成的值并根据它打印消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆