c# – 如何根据ASP.NET中该行的值数据绑定在我的转发器中设置表
发布时间:2020-12-16 00:14:00 所属栏目:百科 来源:网络整理
导读:我有一个转发器控件: table style="width: 100%" asp:Repeater runat="server" ID="rptOptions" OnItemDataBound="rptOptions_ItemDataBound" HeaderTemplate tr td class="GridHeader"Account/td td class="GridHeader"Margin/td td class="GridHeader"Sym
我有一个转发器控件:
<table style="width: 100%"> <asp:Repeater runat="server" ID="rptOptions" OnItemDataBound="rptOptions_ItemDataBound"> <HeaderTemplate> <tr> <td class="GridHeader">Account</td> <td class="GridHeader">Margin</td> <td class="GridHeader">Symbol</td> <td class="GridHeader">Price</td> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td class="GridRow"><asp:Label runat="server" ID="lblOptionAccount"></asp:Label></td> <td class="GridRow"><asp:Label runat="server" ID="lblOptionMargin"></asp:Label></td> <td class="GridRow"><asp:Label runat="server" ID="lblOptionSymbol"></asp:Label></td> <td class="GridRow"><asp:Label runat="server" ID="lblOptionPrice"></asp:Label></td> </tr> </ItemTemplate> </asp:Repeater> </table> 以下代码隐藏数据绑定方法: protected void rptOptions_ItemDataBound(object sender,RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Option rowOption = (Option)e.Item.DataItem; ((Label)e.Item.FindControl("lblOptionAccount")).Text = rowOption.Account; ((Label)e.Item.FindControl("lblOptionMargin")).Text = rowOption.Margin ? "Y" : "N"; ((Label)e.Item.FindControl("lblOptionSymbol")).Text = rowOption.Symbol; ((Label)e.Item.FindControl("lblOptionPrice")).Text = rowOption.Price.ToString("C",currencyFormat); } } 该网格中有更多列,但我只是针对这个问题进行了细化. 现在,我想要做的是根据价格金额更改tr的背景颜色.如果它在不同的级别,我想相应地改变行背景颜色. 我是否必须使用javascript执行此操作,或者是否有某些方法可以访问代码隐藏中的表行以设置此颜色? 解决方法
使它成为runat =“Server”
<tr runat="server" ID="trHeader"></tr> 然后在数据绑定事件中的代码后面找到ID表中的ID,就像你正在为其他服务器端控件做的那样并改变颜色. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- c# – 如何确保Task.Factory.StartNew不会减慢主线程的速度
- 关于sax解析XML文件的简单流程+工具类
- WCF服务编程设计规范(9):中文、中英文对照、英文版资料共享
- 如何在Oracle上获取SYSDATE的UTC值
- postgresql – Postgres 8.3:“错误:缓存计划不能更改结果
- Oracle11gR2_RAC_for_redhat6.3 安装手册
- ruby-on-rails – Ruby(使用Rails)将一串时间转换为秒?
- C中的枚举不会在无效输入上引发错误
- actionscript – Flash Player神奇的帧速率
- 再弄一片文章凑个4篇文章的数,主要是用于XML和 Binary序列