Solved

ASP.net GridView Template column behaving strangely

Posted on 2013-06-08
9
495 Views
Last Modified: 2013-06-13
Hi

I have the following GridView with four DropDownList template columns.
After data binding the second one doesn't show properly.
I can't find any of my code that would affect it. The image shows how it looks

<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>

1
0
Comment
Question by:murbro
9 Comments
 
LVL 12

Expert Comment

by:Jitendra Patil
ID: 39231237
can you post your .cs code for binding gridview.
0
 

Author Comment

by:murbro
ID: 39231242
Sub Load_GridView_with_Survey(ByVal oSQL As String)

        Try

            ' Run the query and bind the resulting DataSet
            ' to the GridView control.
            Dim ds2 As DataSet = GetData(oSQL)
            If (ds2.Tables.Count > 0) Then

                Me.GridView2.DataSource = ds2
                Me.GridView2.DataBind()

            Else

                'Me.Label_Error1.Text = "Unable to connect to the database. " & Err.Description

            End If


        Catch ex As Exception
            Me.Label1.Text = ex.Message
        End Try
    End Sub
0
 

Author Comment

by:murbro
ID: 39231253
I built some code that loops through the cells, picking up their values and once it had finished
the missing DropDownList appeared
0
 
LVL 8

Expert Comment

by:rpkhare
ID: 39231255
What exactly you are getting in DataSet? Are there any bound fields in your GridView code?

Post complete HTML code of GridView.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:murbro
ID: 39231264
I bind data from a SQL database to the GridView
<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
 
LVL 8

Expert Comment

by:rpkhare
ID: 39231270
Here I am not seeing any bound fields. Why you are binding with a DataSet? What you are getting in DataSet and what you are trying to achieve?
0
 

Author Comment

by:murbro
ID: 39231389
I changed the binding code to the following and the same thing happened.
All my GridView loads are a set of Questions, where the user selects answers from the template dropdowns


    Sub Load_Questions_GridView(ByVal oSQL As String)
        Try

            Dim cs As String = ConfigurationManager.ConnectionStrings("Tests_conn").ConnectionString
            Dim connection As New SqlConnection(cs)
            Dim dataadapter As New SqlDataAdapter(oSQL, connection)
            Dim ds As New DataSet()
            connection.Open()
            dataadapter.Fill(ds, "My_table")
            connection.Close()
            GridView2.DataSource = ds
            GridView2.DataMember = "My_table"
            GridView2.DataBind()

        Catch ex As Exception
            Response.Write(ex.Message)
        End Try
    End Sub
0
 
LVL 20

Accepted Solution

by:
informaniac earned 500 total points
ID: 39232498
<asp:GridView ID="GridView2" runat="server" 
    font-names="Century Gothic" forecolor="White" style="margin-top: 0px" AutoGenerateColumns="false">

Open in new window

0
 

Author Closing Comment

by:murbro
ID: 39245598
Thanks for the help
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video discusses moving either the default database or any database to a new volume.
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…

707 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

14 Experts available now in Live!

Get 1:1 Help Now