Solved

ASP.net VB.net Looping through Gridview template columns to gather selected values in drop downs

Posted on 2013-06-08
2
755 Views
Last Modified: 2013-06-08
Hi

I have a GridView with 4 Template column DropDownList columns.
They appear as the first four columns.
How do I gather the selected values of these dropdowns.
My VB.net code below doesn't work.

<asp:GridView ID="GridView2" runat="server"
    font-names="Century Gothic" forecolor="White" style="margin-top: 0px">
                <Columns>
                   
                     <asp:TemplateField HeaderText="A">
                     <ItemTemplate>
                          <asp:DropDownList ID="ddlOptions" runat="server">
                                <asp:ListItem></asp:ListItem>
                                <asp:ListItem>1st</asp:ListItem>
                                <asp:ListItem>2nd</asp:ListItem>
                                <asp:ListItem>3rd</asp:ListItem>
                                <asp:ListItem>4th</asp:ListItem>
                         </asp:DropDownList>
                     </ItemTemplate>
                     </asp:TemplateField>

             


                     <asp:TemplateField HeaderText="B">
                     <ItemTemplate>
                          <asp:DropDownList ID="ddlOptions2" runat="server">
                                <asp:ListItem></asp:ListItem>
                                <asp:ListItem>1st</asp:ListItem>
                                <asp:ListItem>2nd</asp:ListItem>
                                <asp:ListItem>3rd</asp:ListItem>
                                <asp:ListItem>4th</asp:ListItem>
                         </asp:DropDownList>
                     </ItemTemplate>
                     </asp:TemplateField>

                     <asp:TemplateField HeaderText="C">
                     <ItemTemplate>
                          <asp:DropDownList ID="ddlOptions3" runat="server">
                                <asp:ListItem></asp:ListItem>
                                <asp:ListItem>1st</asp:ListItem>
                                <asp:ListItem>2nd</asp:ListItem>
                                <asp:ListItem>3rd</asp:ListItem>
                                <asp:ListItem>4th</asp:ListItem>
                         </asp:DropDownList>
                     </ItemTemplate>
                     </asp:TemplateField>

                     <asp:TemplateField HeaderText="D">
                     <ItemTemplate>
                          <asp:DropDownList ID="ddlOptions4" runat="server">
                                <asp:ListItem></asp:ListItem>
                                <asp:ListItem>1st</asp:ListItem>
                                <asp:ListItem>2nd</asp:ListItem>
                                <asp:ListItem>3rd</asp:ListItem>
                                <asp:ListItem>4th</asp:ListItem>
                         </asp:DropDownList>
                     </ItemTemplate>
                     </asp:TemplateField>
                   

                    <asp:TemplateField HeaderText="Question">
                        <ItemTemplate>
                         </ItemTemplate>
                    </asp:TemplateField>




                    <asp:TemplateField HeaderText="Answer">
                   
                        <ControlStyle BackColor="#CCCCCC" />
                   
                    </asp:TemplateField>

                </Columns>
            </asp:GridView>
0
Comment
Question by:murbro
2 Comments
 
LVL 20

Accepted Solution

by:
informaniac earned 500 total points
Comment Utility
There is no code attached here.

If you are using a SQL DataSource doing a FindControl might not work.

foreach(GridViewRow gvRow in grid1.Rows)
{
      DropdownList ddl1 = gvRow.FindControl("ddlOptions4") as DropdownList;
      string strSelectedValue = ddl1.SelectedValue;
}

Open in new window

0
 

Author Closing Comment

by:murbro
Comment Utility
Thanks very much
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now