如何在asp.net中的转发器中使用用户控件属性 [英] how to use user control properties in a repeater in asp.net
本文介绍了如何在asp.net中的转发器中使用用户控件属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个转发器,我添加了一个用户控件,
用户控件包含一些文本框ni已经分配了它的属性。
i希望使用转发器中的那些属性来保存usercontrol中给出的文本。
aspx代码:
Hi guys,
I have a repeater where i have added one user control,
the user control contains some text boxes n i have assigned its properties also.
i want to use to those properties from repeater to save the text given in usercontrol.
aspx code:
<table>
<tr>
<td style="width: 100px">
<asp:Label ID="Label2" runat="server" Text="No.Items" Font-Bold="true"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtno" runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnadd" runat="server" CssClass="btn btn-warning" Text="Add More"
OnClick="btnadd_Click" />
</td>
</tr>
</table>
<asp:Repeater ID="Repeater1" runat="server" >
<HeaderTemplate>
<table class="table table-bordered table-hover">
<thead class="bg-dark lt">
<tr>
<th>
S.No#
</th>
<th><table><tr>
<th align="center" style="width: 300px">
Item
</th>
<th align="center" style="width: 405px">
Description
</th>
<th align="center" style="width: 350px">
Quantity
</th>
<th align="center" style="width: 300px">
Remarks
</th></tr></table></th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# Container.ItemIndex + 1 %>
</td>
<td>
<uc1:pousercontrol ID="pousercontrol1" runat="server" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody> </table>
</FooterTemplate>
</asp:Repeater>
aspx.cs:
aspx.cs:
protected void btnadd_Click(object sender, EventArgs e)
{
int i = Convert.ToInt32(txtno.Text);
Repeater1.DataSource = Enumerable.Range(0, i);
Repeater1.DataBind();
btnadd.Enabled = false;
}
i试过这个,保存按钮代码:
i tried this, save button code:
protected void btnSave_Click(object sender, EventArgs e)
{
foreach (RepeaterItem item in Repeater1.Items)
{
UserControl uc = (UserControl)item.FindControl("pousercontrol1");
//unable to get the properties
}
}
plz帮助人们。
thankz
plz help guys.
thankz
推荐答案
foreach (RepeaterItem item in rpt1.Items)
{
UserControl uc = (UserControl)item.FindControl("uc_textbox");
TextBox tb = (TextBox)uc.FindControl("txt1");
Response.Write(tb.Text);
}
这篇关于如何在asp.net中的转发器中使用用户控件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文