• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 534
  • Last Modified:

Visual Studio 2008 asp vb code: Binding SQLDatasource output to gridview with Textboxes

I am having a slight bit of trouble getting my output to show up as I would like. Please take a look at this snippet. As always, I have tried to dumb down the example as much as possible, changing variable names what not so this is a basic example that is hopefully easy to read and understand:

<asp:SqlDataSource ID="SqlDataSourceNames" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" EnableViewState="False"  

SelectCommand="SELECT DISTINCT table1.ForName, table1.Counts FROM table1 LEFT OUTER JOIN table2 on table1.1 = table2.1 WHERE (table2.3 = @my3) AND (table2.4 = @my4) AND (table2.5 = @my5) AND (table2.6 = @my6)">
<asp:SessionParameter Name="my3" SessionField="Sess3" />
<asp:SessionParameter Name="my4" SessionField="Sess4" />
<asp:SessionParameter Name="my5" SessionField="Sess5" />
<asp:SessionParameter Name="my6" SessionField="Sess6" />
<asp:GridView ID="GridViewMyList" runat="server" BorderStyle="None" BorderWidth="0px" CellSpacing="5" DataSourceID="SqlDataSourceNames" EnableViewState="False" ShowFooter="True">
      <asp:TemplateField HeaderText="Count Num:">
               <asp:TextBox ID="TextBox0" runat="server" Columns="3" Text='<%# Bind("Counts") %>'></asp:TextBox>
      <asp:TemplateField HeaderText="My List of Names:">
               <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ForName") %>'></asp:TextBox>
          <FooterStyle HorizontalAlign="left" />
                   <asp:Button ID="ButtonUpdateCounts" runat="server" Text="Update Counts" />

Open in new window

What I intend to end up with is two columns, each with textboxes containing the data from the two fields coming out of the sqldatasource query. There would also be a footer at the bottom with a button to update the counts...

Count Num: | My List of Names: |
[__3__]                   [___Tom___]            
[__4__]                   [___John___]            
[__2__]                   [___Steve___]          

                             [__Update Counts__]

What I am ACTUALLY getting is four columns. Two show up the way I want them to in text boxes, but I also get two columns as text only with the names and counts....

Count Num: | My List of Names: | ForName | Counts
[__3__]                   [___Tom___]            Tom              3
[__4__]                   [___John___]            John              4
[__2__]                   [___Steve___]          Steve             2

                             [__Update Counts__]

Clearly, some minor detail in how I am setting up the code is going to make the difference for me, but I have not identified what needs to be changed. Any help would be appreciated and expert points are waiting to be awarded.
1 Solution
Obadiah ChristopherCommented:
<asp:GridView ID="GridViewMyList" runat="server" BorderStyle="None" BorderWidth="0px" CellSpacing AutoGenerateColumns="false"
SullivanMISAuthor Commented:
Well that was easy...

AutoGenerateColumns = "False" solved my problem
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now