c#如何获取repeater中某一行某一列文本框的值 文本框没有id

文本框是由repeater循环出来的,所以id不确定,每行有三个文本框。我想for循环遍历repeater中的文本框中的值。求大神帮解答。主要要代码... 文本框是由repeater循环出来的,所以id不确定,每行有三个文本框。 我想for循环遍历repeater中的文本框中的值。求大神帮解答。 主要要代码 展开
 我来答
suqifeng2009
推荐于2016-02-11 · TA获得超过103个赞
知道小有建树答主
回答量:127
采纳率:0%
帮助的人:77.2万
展开全部
//后台获取
 protected void btnPay_Click(object sender, EventArgs e)
    {
        if (rptMest.Items.Count > 0)
        {

            List<Model.Pay> listPayModel = new List<Model.Pay>();
            foreach (RepeaterItem rptitem in this.rptMest.Items)
            {
                payModel = new Model.Pay();
                HiddenField hfID = (HiddenField)rptitem.FindControl("hfID");
                Label lblFee = rptitem.FindControl("lblFee") as Label;
                TextBox txtPayment = rptitem.FindControl("txtPayment") as TextBox;
                TextBox txtNotes = rptitem.FindControl("txtNotes") as TextBox;
                TextBox txtPayDate = rptitem.FindControl("txtPayDate") as TextBox;
                payModel.OperatingDate = Convert.ToDateTime(txtPayDate.Text);
                payModel.Fee = Convert.ToInt32(lblFee.Text);
                payModel.ManifestID = hfID.Value;
                payModel.CreateUser = CurrentUser.ID;
                payModel.OperatingUser = CurrentUser.ID;
                payModel.Remark = "";
                payModel.Payment = Convert.ToInt32(txtPayment.Text);
                listPayModel.Add(payModel);
            }
            if (payBLL.Add(listPayModel))
            {
                Common.MessageBox.Show(this.Page, "付款处理成功!");
                InitData();
                DataBinds();
            }
            else
            {
                Common.MessageBox.Show(this.Page, "付款处理失败!");
                DataBinds();
            }
        }
    }
 前台绑定
 <asp:Repeater runat="server" ID="rptMest" OnItemCommand="rptMest_ItemCommand" OnItemDataBound="rptMest_ItemDataBound">
                        <ItemTemplate>
                            <tr class="rptTr">
                                <td>
                                    <asp:HiddenField ID="hfID" Value='<%# Eval("ManifestID")%>' runat="server" />
                                    <a onclick='ShowFrame(<%# Eval("ManifestID")%>)' title="点击查看货单详情" href="javascript:void(0)">
                                        <%# Eval("ManifestID")%>
                                    </a>
                                </td>
                                <td>
                                    <asp:Label ID="lblDate" runat="server" Text='<%# Eval("Date","{0:yyyy-MM-dd}")%>'></asp:Label>
                                </td>
                                <td >
                                    <asp:Label ID="lblShipper" runat="server" Text='<%# Eval("Shipper")%>'></asp:Label>
                                </td>
                                <td>
                                    <asp:Label ID="lblConsignee" runat="server" Text='<%# Eval("Consignee")%>'></asp:Label>
                                </td>
                                <td>
                                    <asp:Label ID="lblCargoAmount" runat="server" Text='<%# Eval("CargoAmount")%>'></asp:Label>
                                </td>
                                <td>
                                    <asp:Label ID="lblCargoType" runat="server" Text='<%# Eval("CargoType")%>'></asp:Label>
                                </td>
                                <td>
                                    <asp:Label ID="lblPayment" class="dshk" runat="server" Text='<%# Eval("Payment")%>'></asp:Label>
                                </td>
                                <td>
                                    <asp:Label ID="lblCheckoutPayment" class="sshk" runat="server" Text='<%# Eval("CheckoutPayment")%>'></asp:Label>
                                </td>
                                <td>
                                    <asp:Label ID="lblCheckoutNotes" Text='<%# Eval("CheckoutNotes")%>' runat="server"></asp:Label>
                                </td>
                                <td>
                                    <asp:Label ID="lblFee" class="sxf" runat="server" Text=""></asp:Label>
                                </td>
                                <td>
                                    <asp:Label ID="lblYFPayment" class="yfhk" runat="server" Text=""></asp:Label>
                                </td>
                                                                <td>
                                    <asp:TextBox ID="txtPayDate" Width="80px"  onclick="WdatePicker({isShowClear:true,readOnly:false,maxDate:'%y-%M-%d'})" runat="server"></asp:TextBox>
                                </td>
                                <td>
                                    <asp:TextBox ID="txtPayment" class="sfhk" onkeyup="CheckValue(this)" Width="50px"
                                        MaxLength="10" runat="server"></asp:TextBox>
                                </td>

                                <td>
                                    <asp:LinkButton ID="lbnDelete" runat="server" CommandName="Delete">[移除]</asp:LinkButton>
                                </td>
                            </tr>
                        </ItemTemplate>
                    </asp:Repeater>
瑞德1o
2013-10-28 · 超过38用户采纳过TA的回答
知道小有建树答主
回答量:92
采纳率:0%
帮助的人:65.4万
展开全部
protected void rMain_ItemCommand(object source, RepeaterCommandEventArgs e)
{
ImageButton ib = e.Item.FindControl("img") as ImageButton;
int cid = int.Parse(e.CommandArgument.ToString());
if (null != ib)
{
Panel p = e.Item.FindControl("pMain") as Panel;
if (ib.ImageUrl == "~/Images/Up.gif")
{
ib.ImageUrl = "~/Images/Down.gif";
p.Visible = false;

}
else
{
ib.ImageUrl = "~/Images/Up.gif";

p.Visible = true;
IList<PlaneTypeInfo> types = new PlaneTypeDAL().GetAllPlaneTypesByCid(cid);
GridView g = e.Item.FindControl("gvMain") as GridView;
g.DataSource = types;
g.DataBind();
}
}
}
只要在ItemCommand和ItemDataBound事件中,都可以通过e.Item.FindControl("控件的id")来查找控件.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式