c#如何获取repeater中某一行某一列文本框的值 文本框没有id
文本框是由repeater循环出来的,所以id不确定,每行有三个文本框。我想for循环遍历repeater中的文本框中的值。求大神帮解答。主要要代码...
文本框是由repeater循环出来的,所以id不确定,每行有三个文本框。 我想for循环遍历repeater中的文本框中的值。求大神帮解答。 主要要代码
展开
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>
展开全部
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")来查找控件.
{
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")来查找控件.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询