Solved

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

Posted on 2013-06-08
2
765 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Validation for a field in asp.net 3 31
aspx ascx, c# 7 43
EF5 How do I stop pre-compiled views? 8 54
Suppress if value zero or NULL in crystal report 2 43
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

738 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