Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 526
  • 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
<asp:GridView ID="GridViewMyList" runat="server" BorderStyle="None" BorderWidth="0px" CellSpacing AutoGenerateColumns="false"
SullivanMISAuthor Commented:
Well that was easy...

AutoGenerateColumns = "False" solved my problem

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

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