Solved

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

Posted on 2013-06-08
2
762 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
ID: 39232491
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
ID: 39232522
Thanks very much
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 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