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

Posted on 2012-08-27
Last Modified: 2012-08-27
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.
Question by:SullivanMIS
    LVL 20

    Accepted Solution

    <asp:GridView ID="GridViewMyList" runat="server" BorderStyle="None" BorderWidth="0px" CellSpacing AutoGenerateColumns="false"

    Author Comment

    Well that was easy...

    AutoGenerateColumns = "False" solved my problem

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    734 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

    24 Experts available now in Live!

    Get 1:1 Help Now