充分利用在asp.net Repeater控件数据绑定值 [英] Getting the databound value from repeater control in asp.net

查看:158
本文介绍了充分利用在asp.net Repeater控件数据绑定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为后续行动,以我的问题<一href=\"http://stackoverflow.com/questions/7043829/looping-through-a-repeater-control-to-get-values-of-textbox-in-asp-net\">Looping通过中继器的控制来获得在asp.net 文本框的值
如果用户在文本框中输入的数量,我想从Repeater控件对应的ProductID值:

As a follow up to my question Looping through a repeater control to get values of Textbox in asp.net If user has entered a a quantity in the textbox, I want to get the corresponding ProductID value from the repeater control:

<asp:Repeater ID="rptRequestForm" runat="server">
                    <HeaderTemplate>
                            <table border="0" width="100%">
                                <tr>
                                    <td style="width:50%" class="TextFontBold"><asp:Label runat="server" ID="Label1" Text="Supply Name"></asp:Label></td>
                                    <td style="width:25%" class="TextFontBold"><asp:Label runat="server" ID="Label2" Text="Quantity"></asp:Label></td>
                                    <td style="width:25%" class="TextFontBold"><asp:Label runat="server" ID="Label3" Text="Price (ea.)"></asp:Label></td>
                                </tr>
                            </table>
                    </HeaderTemplate>
                        <ItemTemplate>
                            <table border="0" width="100%">
                                <tr>
                                    <td style="width:50%" class="TextFont"><asp:Label ID="lblProductName" Text="<%#Trim(Eval("Product_Title"))%>" ><%#Trim(Eval("Supplie_title"))%></asp:Label></td>
                                    <td style="width:25%"><asp:TextBox ID="txtBox" runat="server" Width="30%" onblur="Javascript:numberonly(this)"></asp:TextBox></td>
                                    <td style="width:25%" class="TextFont"><span><%#Trim(FormatCurrency(Eval("Price")))%></span></td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </asp:Repeater> 

我的codebehind是:

My codebehind is:

For Each item As RepeaterItem In rptRequestForm.Items
                txtField = item.FindControl("txtBox")
                If Not IsNothing(txtField) Then
                    j += 1
                    strText = strText & ", " & txtField.Text
                End If
Next

我使用的FindControl通过文本框循环

(查看是否用户输入有效的数量)。我怎样才能得到相应的ProductID的价值?

I am using FindControl to loop through the textbox (to see if user has entered a valid quantity). How can I get the value of the corresponding ProductID ?

推荐答案

标签添加到您的ItemTemplate,像这样的:

Add a label to your ItemTemplate, like this:

<td style="width:50%" class="TextFont"><asp:Label ID="lblProductName" runat="server"><%#Trim(Eval("Product_Title"))%></asp:Label></td>

而在你的code后面,发现它是这样的:

And in your code behind, find it like this:

foreach (RepeaterItem item in Repeater1.Items)
{
    TextBox txtField = (TextBox)item.FindControl("txtBox");

    //extract value from textbox
    int Quantity = Convert.ToInt32(((TextBox)item.FindControl("txtBox").Text);

    //extract the value from the label
    string productName = ((Label)item.FindControl("lblProductName")).Text;
}

这篇关于充分利用在asp.net Repeater控件数据绑定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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