加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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,就像你正在为其他服务器端控件做的那样并改变颜色.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读