选择在直放站项目或列和更改数据 [英] Selecting an Item or column in a Repeater and changing the Data

查看:97
本文介绍了选择在直放站项目或列和更改数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变我的中继数据
到目前为止,我的每一行通过项目和循环AlternatingItem
但我想改变的最后一列中的值
所以该值到小数点后两位。我有一个基本的
连接到填充中继器的存储过程
低于code:

连接到存储过程:

  SqlDataAdapter的大=新SqlDataAdapter的(存储过程,康恩);
    da.SelectCommand.CommandType = CommandType.StoredProcedure;
    da.SelectCommand.Parameters.Add(新的SqlParameter(@联系,ALL));
    数据集的数据集=新的DataSet();
    da.Fill(数据);
    rptItems.DataSource = dataset.Tables [0];
    rptItems.DataBind();

code代表的ItemDataBound方法:

 保护无效rptconsole_ItemDataBound(对象发件人,RepeaterItemEventArgs E)
    {
        如果(e.Item.ItemType == || ListItemType.Item == e.Item.ItemType ListItemType.AlternatingItem)
        {
           // code应该在这里它改变了最后一列的值
           //到小数点后两位
        }
    }

HTML / XAML code来填充转发

 < ASP:直放站ID =rptconsole=服务器OnItemDataBound =rptconsole_ItemDataBound>       <&HeaderTemplate中GT;            <表ID =tablework>                <第i控制台< /第i
                <第i颜色和LT; /第i
                <第i个特征与LT; /第i
                <第i说明< /第i
                <第i的价格和LT; /第i< / HeaderTemplate中>
        <&ItemTemplate中GT;            &所述; TR>
                < TD ALIGN =中心><%#的eval([ConsoleType])%GT;< / TD>
                < TD ALIGN =中心><%#的eval([颜色])%GT;< / TD>
                < TD ALIGN =中心><%#的eval([特征])%GT;< / TD>
                < TD ALIGN =中心><%#的eval([DESC])%GT;< / TD>
                < TD ALIGN =中心><%#的eval([价格])%GT;< / TD>
            < / TR>
        < / ItemTemplate中>
        < AlternatingItemTemplate>            &所述; TR>
        < TD ALIGN =中心><%#的eval([ConsoleType])%GT;< / TD>
                < TD ALIGN =中心><%#的eval([颜色])%GT;< / TD>
                < TD ALIGN =中心><%#的eval([特征])%GT;< / TD>
                < TD ALIGN =中心><%#的eval([DESC])%GT;< / TD>
                < TD ALIGN =中心><%#的eval([价格])%GT;< / TD>
            < / TR>
        < / AlternatingItemTemplate>        < FooterTemplate>
            < /表>
        < / FooterTemplate>
    < / ASP:直放站>


解决方案

您不需要使用OnItemDataBound事件,在所有。

您可以像下面这样做在ASP标记:

  ...
< TD =服务器ID =价格ALIGN =中心><%#的String.Format({0:F2}的eval([价格]))%>< / TD>
...

或者,如果你想使用.NET货币格式:

  ...
< TD =服务器ID =价格ALIGN =中心><%#的String.Format({0:C}的eval([价格]))%>< / TD>
...

检查这篇文章有关.NET标准数字格式字符串的更具体信息:的 http://msdn.microsoft.com/en-us/library/dwhawy9k(v = vs.110)的.aspx

I am trying to change the data in my repeater so far I am cycling through each row by Item and AlternatingItem but I want change the values in the last column so that the value is to two decimal places. I have a basic Connection to a stored procedure which populates the repeater code below:

connection to the stored procedure:

    SqlDataAdapter da = new SqlDataAdapter("Stored Procedure", conn);
    da.SelectCommand.CommandType = CommandType.StoredProcedure;
    da.SelectCommand.Parameters.Add(new SqlParameter("@Admin", "ALL"));
    DataSet dataset = new DataSet();
    da.Fill(dataset);
    rptItems.DataSource = dataset.Tables[0];
    rptItems.DataBind();

Code for the ItemDataBound method:

    protected void rptconsole_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType  ==ListItemType.AlternatingItem)
        {
           //Code should go here which changes the values of the last column
           //To two decimal places
        }
    }

html/XAML code to populate the repeater:

<asp:Repeater ID="rptconsole" runat="server" OnItemDataBound="rptconsole_ItemDataBound">

       <HeaderTemplate>

            <table id="tablework">

                <th>Console</th>
                <th>Color</th>
                <th>Features</th>
                <th>Description</th>
                <th>price</th>

</HeaderTemplate>
        <ItemTemplate>

            <tr>
                <td align="center"><%# Eval("[ConsoleType]") %></td>
                <td align="center"><%# Eval("[color]") %></td>
                <td align="center"><%# Eval("[features]") %></td>
                <td align="center"><%# Eval("[desc]") %></td>
                <td align="center"><%# Eval("[price]") %></td>
            </tr>


        </ItemTemplate>
        <AlternatingItemTemplate>

            <tr>
        <td align="center"><%# Eval("[ConsoleType]") %></td>
                <td align="center"><%# Eval("[color]") %></td>
                <td align="center"><%# Eval("[features]") %></td>
                <td align="center"><%# Eval("[desc]") %></td>
                <td align="center"><%# Eval("[price]") %></td>
            </tr>
        </AlternatingItemTemplate>

        <FooterTemplate>
            </table>
        </FooterTemplate> 
    </asp:Repeater>

解决方案

You don't need to use OnItemDataBound event for that at all.

You can do it like this in ASP markup:

...
<td  runat="server" id="price" align="center"><%# String.Format("{0:F2}", Eval("[price]")) %></td>
...

Or if you want to use .NET currency formatting:

...
<td  runat="server" id="price" align="center"><%# String.Format("{0:C}", Eval("[price]")) %></td>
...

Check this article for more specific information about .NET Standard Numeric Format String: http://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx

这篇关于选择在直放站项目或列和更改数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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