views:

1996

answers:

3

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>

+3  A: 

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
Code converter if needed: http://www.developerfusion.com/tools/convert/csharp-to-vb/
Nick
doest seem to be converting
"Statement fragment: please enter a complete statement. "
It's because the semi-colon on the 'TextBox AdFullName ...' line is missing.
Nick
Thanks Nick, added semi-colon.
Mun
Getting this now. Object reference not set to an instance of an object. Line 95: Dim enteredAdFullName As String = AdFullName.Text
fixed it. my fault! sorry. Thanks for your help!!
A: 

and how can you get the value if you have a repeater in a repater

A: 

This is very neat Code.I just used into my implementation.Thanks for posting.

Harman