1

ok, ive had a few questions on this subject, i hope Im clearer this time.

I want to find the values from a number of dropdown controls inside a repeater control. I eventually want to build a multidimensional array, so I can loop through each item and add them to a database table.

<asp:Repeater ID="myRepeater" runat="server">
<ItemTemplate>
     <asp:DropDownList ID="AdTitle" runat="server">
         <asp:ListItem Selected="True" Value="" Text=""/>
         <asp:ListItem Selected="False" Value="Miss" Text="Miss"/>
         <asp:ListItem Selected="False" Value="Ms" Text="Ms"/>
         <asp:ListItem Selected="False" Value="Mrs" Text="Mrs"/>
         <asp:ListItem Selected="False" Value="Mr" Text="Mr"/>
         <asp:ListItem Selected="False" Value="Other" Text="Other"/>
     </asp:DropDownList>

     <asp:TextBox ID="AdFullName" runat="server"></asp:TextBox>
</ItemTemplate>

<ItemTemplate>
     <asp:DropDownList ID="AdTitle" runat="server">
         <asp:ListItem Selected="True" Value="" Text=""/>
         <asp:ListItem Selected="False" Value="Miss" Text="Miss"/>
         <asp:ListItem Selected="False" Value="Ms" Text="Ms"/>
         <asp:ListItem Selected="False" Value="Mrs" Text="Mrs"/>
         <asp:ListItem Selected="False" Value="Mr" Text="Mr"/>
         <asp:ListItem Selected="False" Value="Other" Text="Other"/>
     </asp:DropDownList>

     <asp:TextBox ID="AdFullName" runat="server"></asp:TextBox>
</ItemTemplate>

1 Answers1

6

You would need to loop through the repeater items and get each value. Code sample below is in C#, but should be able to convert to VB.NET relatively easily.

foreach (RepeaterItem ri in myRepeater.Items)
{
    switch (ri.ItemType)
    {
        case ListItemType.Item:
        case ListItemType.AlternatingItem:

            DropDownList AdTitle = (DropDownList) ri.FindControl("AdTitle");
            TextBox AdFullName = (TextBox) ri.FindControl("AdFullName");

            string selectedAdTitle = AdTitle.SelectedValue;
            string enteredAdFullName = AdFullName.Text;

            // Do something with values here

        break;
    }
}
Mun
  • 14,098
  • 11
  • 59
  • 83
  • Code converter if needed: http://www.developerfusion.com/tools/convert/csharp-to-vb/ – Nick May 31 '09 at 16:02
  • "Statement fragment: please enter a complete statement. " –  May 31 '09 at 16:05
  • It's because the semi-colon on the 'TextBox AdFullName ...' line is missing. – Nick May 31 '09 at 16:08
  • Getting this now. Object reference not set to an instance of an object. Line 95: Dim enteredAdFullName As String = AdFullName.Text –  May 31 '09 at 16:17
  • fixed it. my fault! sorry. Thanks for your help!! –  May 31 '09 at 16:22