Advertisement

05.22.2008 at 07:55AM PDT, ID: 23424633
[x]
Attachment Details

Why does GridView display columns twice?

Asked by mrcoulson in Microsoft Visual Basic.Net, WebApplications

Tags: Visual Basic .Net, Firefox 2

I have a GridView that is supposed to display data from a SQL Server Express database.  It does this.  Unfortunately, it displays each column twice.  Why for?  I've tried removing the SqlDataSource1.SelectCommand and asp:SqlDataSource SelectCommand="SELECT * FROM [Table_1]" alternatively, but I still get the data displaying twice.

I've included my code.  I'm new at this, so don't be too harsh about my code or the fact that my SQL is not secured.  One step at a time! Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
<%@ Page Language="VB" %>
 
<script language="vb" runat="server">
    
    Sub insertHandler(ByVal sender As Object, ByVal e As EventArgs)
        SqlDataSource1.InsertCommand = "INSERT INTO [Table_1] ([person_name], [person_iq]) VALUES ('" + strPersonName.Text + "', '" + strPersonIQ.Text + "');"
        SqlDataSource1.Insert()
        lbl1.Text = "person_name = " + strPersonName.Text
        lbl2.Text = "person_iq = " + strPersonIQ.Text
    End Sub
    
    Sub selectHandler(ByVal sender As Object, ByVal e As EventArgs)
        SqlDataSource1.SelectCommand = "SELECT [person_name], [person_iq] FROM [Table_1]"
        SqlDataSource1.Select(DataSourceSelectArguments.Empty)
        GridView1.Visible = True
    End Sub
 
</script>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<script runat="server">
 
</script>
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Name:&nbsp;&nbsp;<asp:TextBox ID="strPersonName" runat="server" Width="14.5em" tabindex="1" /><br />
        IQ:&nbsp;&nbsp;<asp:TextBox ID="strPersonIQ" runat="server" Width="14.5em" TabIndex="2" /><br />
        <asp:Button ID="btnInsert" runat="server" text="INSERT INTO [Table_1] ([person_name], [person_iq]) VALUES ('&quot; + strPersonName.Text + &quot;', '&quot; + strPersonIQ.Text + &quot;')" onClick="insertHandler" tabindex="3"/><br /><br />
        <asp:Label ID="lbl1" runat="server" /><br />
        <asp:Label ID="lbl2" runat="server" /><br /><br />
        <asp:Button ID="btnSelect" runat="server" Text="SELECT [person_name], [person_iq] FROM [Table_1]" OnClick="selectHandler" TabIndex="4" />
        <br /><br />
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="True" DataSourceID="SqlDataSource1" AllowSorting=true RowHeaderColumn="person_name" EmptyDataText="Zee database is empty!" Visible=false>
            <Columns>
                <asp:BoundField DataField="person_name" HeaderText="Name" SortExpression="person_name" />
                <asp:BoundField DataField="person_iq" HeaderText="IQ" SortExpression="person_iq" />
            </Columns>
        </asp:GridView>
        
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:insert_schoolConnectionString %>"
            SelectCommand="SELECT * FROM [Table_1]"></asp:SqlDataSource>
    
    </div>
    </form>
</body>
</html>
Attachments:
 
screen shot of gridview
screen shot of gridview
 
[+][-]05.22.2008 at 10:58AM PDT, ID: 21626085

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual Basic.Net, WebApplications
Tags: Visual Basic .Net, Firefox 2
Sign Up Now!
Solution Provided By: AshleyBryant
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628