0

我有一个表单,允许用户更新他们的个人资料和联系信息。我使用 div 标签内的 asp:repeater 控件创建了这个表单。我在其中有 4 个 div 标签,其中包含其他控件,如文本框和下拉列表。我只想知道,我如何访问中继器控件中的控件。我给出的代码:

<tr>
<td class="directorytdWidth">
Gender:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtGender" runat="server"    Width="100px" Text='<%#Eval("gender")%>'></asp:TextBox>
<asp:RadioButtonList ID="radioGender" runat="server" RepeatColumns="2" Visible="false">
<asp:ListItem Text="Male" Value="M"></asp:ListItem>
<asp:ListItem Text="Female" Value="F">  </asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Address:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtAdd" runat="server" Width="200px"     Text='<%#Eval("candiAddress")%>'
TextMode="MultiLine" Height="75px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Country:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtCountry" runat="server" Width="150px" Text='<%#Eval("countryName")%>'></asp:TextBox>
<asp:DropDownList ID="drpCountry" runat="server"    SelectedValue='<%#Eval("countryName")%>' Width="150px" Height="24px" Visible="false"
AutoPostBack="true"   OnSelectedIndexChanged="drpCountry_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
State:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtState" runat="server"    Width="150px" Text='<%#Eval("stateName")%>'></asp:TextBox>
<asp:DropDownList ID="drpState" runat="server" SelectedeValue='<%#Eval("stateName")%>' Width="150px" Visible="false" Height="24px"
AutoPostBack="true" OnSelectedIndexChanged="drpState_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
City:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtCity" runat="server" Width="150px"     Text='<%#Eval("cityName")%>'></asp:TextBox>
<asp:DropDownList ID="drpCity" runat="server" Width="150px" Height="24px" Visible="false"
AutoPostBack="true">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Postal Code:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtPostalCode" runat="server"    Width="150px" Text='<%#Eval("pincode")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Landline:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtLandline" runat="server" Width="150px" Text='<%#Eval("landline")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Mobile Number:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtMobile" runat="server" Width="150px" Text='<%#Eval("mobile")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Date of Birth:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtDob" runat="server" Width="150px" Text='<%#Eval("dob")%>'></asp:TextBox>
<asp:DropDownList ID="drpYear" runat="server" Visible="false" Height="24px" Width="80px"
AutoPostBack="true">
</asp:DropDownList>
&nbsp;&nbsp;
<asp:DropDownList ID="drpMonth" runat="server"    Height="24px" Width="80px" OnSelectedIndexChanged="drpMonth_SelectedIndexChanged"
AutoPostBack="true" Visible="false">
<asp:ListItem Value="1" Selected="True">January</asp:ListItem>
<asp:ListItem Value="2">February</asp:ListItem>
<asp:ListItem Value="3">March</asp:ListItem>
<asp:ListItem Value="4">April</asp:ListItem>
<asp:ListItem Value="5">May</asp:ListItem>
<asp:ListItem Value="6">June</asp:ListItem>
<asp:ListItem Value="7">July</asp:ListItem>
<asp:ListItem Value="8">August</asp:ListItem>
<asp:ListItem Value="9">September</asp:ListItem>
<asp:ListItem Value="10">October</asp:ListItem>
<asp:ListItem Value="11">November</asp:ListItem>
<asp:ListItem Value="12">December</asp:ListItem>
</asp:DropDownList>
&nbsp;&nbsp;
<asp:DropDownList ID="drpDate" runat="server"    Height="24px" Width="50px" Visible="false"
AutoPostBack="true">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Email Address:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtEmail" runat="server" Width="150px" Text='<%#Eval("altEmail")%>'></asp:TextBox>
</td>
</tr>

在这个我有下拉选定的索引更改事件,所以如何触发这个事件,我还想定义可以在下拉事件中访问的函数。因为当我定义函数时,我无法在中继器控件中获取控件。所以请给我任何解决方案。在此先感谢....

4

2 回答 2

1

不确定您要访问哪些控件,但

1)让他们 runat="server" 并给他们ID

2) 将事件处理程序添加到转发器ItemCreated,或ItemDataBound事件

3)这样的访问控制:

    void R1_ItemCreated(Object Sender, RepeaterItemEventArgs e) {
          var label = (Label)e.Item.FindControl("YourItemId")  
    }
于 2013-06-09T07:12:33.137 回答
0

一旦下拉事件位于转发器控件中,您将无法访问它们。CommandName您可以使用和CommandArgumnentItemCommand转发器事件中对按钮执行操作。

但是你可以做一个解决方法。将下拉列表从中继器中取出,生成其SelectedIndexChanged事件和AutoPostback="true". 然后放回中继器。现在,您可以在代码后面的事件中执行您的操作。我曾经这样做过,但这不是好方法。

于 2013-06-10T06:45:34.337 回答