Link to home
Start Free TrialLog in
Avatar of JB4375
JB4375Flag for United States of America

asked on

ASP Gridview Doesn't Display OR Displays Twice

I started out with a with form that submits to a SQL table, and below that is a grid that displays the contents of the table. I know need to be able to edit the rows in the grid view. So I went back to drawing board and created the grid view with a SQL connection.

My problem is that gridview doesn't show at all. Unless I click on the view file button which call the old get data sub directory. When I do this the table is displayed twice in one long set of rows. I've tried removing the SQL connection in both places but get the same result.


I would prefer, what ever the solution is, that I can call it on load from the VB side.
Thanks.

PS I've left the SQL connection in both places so you could get an idea of what's going on.
default.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Theme="Theme1" Inherits="add_account_excel._Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Zone Manager New Department Request Form </title>
    <link href="default.css" rel="stylesheet" type="text/css" />
    <meta content="True" name="vs_snapToGrid" />
	<meta content="True" name="vs_showGrid" />
    <meta content="JavaScript" name="vs_defaultClientScript" />
</head>
<body>
    <form id="form1" method="post" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    
        <div class="header_container">
            <asp:Image ID="Logo" runat="server" ImageUrl="~/images/wfubmclogo.jpg" />
            <asp:Label ID="lblGold" runat="server" Text="zone manager"></asp:Label>
            <asp:Label ID="lblBlack" runat="server" Text="New Department Request Form"></asp:Label>     
	    </div><!-- end #header-containter -->
	    
    <div id="wrapper">
 
    <div id="content">
        <div class="main-container">
            <div id="right"> 
                <asp:Label ID="Label2" runat="server" Text="Department Name:"></asp:Label><br />
                <asp:TextBox ID="TextBox2" tabindex="2" runat="server"></asp:TextBox><br />
                <asp:Label ID="label19" runat="server" Text="Example: Dermatology" Font-Size="Smaller"></asp:Label><br /><br />
                
                <asp:Label ID="Label4" runat="server" Text="Department OU:"></asp:Label><br />
                <asp:TextBox ID="TextBox4" tabindex="4" runat="server"></asp:TextBox><br />
                <asp:Label ID="label21" runat="server" Text="Example: Derm_1530_Dermatology" Font-Size="Smaller"></asp:Label><br /><br />
              
                <asp:Label ID="Label6" runat="server" Text="Groups:"></asp:Label><br />
                <asp:TextBox ID="TextBox6" tabindex="6" runat="server"></asp:TextBox><br />
                <asp:Label ID="label23" runat="server" Text="Example: Dermatology" Font-Size="Smaller"></asp:Label><br /><br />
                          
                <asp:Label ID="Label8" runat="server" Text="Admin Contact Phone:"></asp:Label><br />
                <asp:TextBox ID="TextBox8" tabindex="8" runat="server"></asp:TextBox><br /><br />
               
                <asp:Label ID="Label10" runat="server" Text="Zone Manager:"></asp:Label><br />
                <asp:TextBox ID="TextBox10" tabindex="10" runat="server"></asp:TextBox><br /><br />  
                <div class="right-container">Right</div>
            </div> <!-- end #right -->    
                        
             <div id="left">  
                <asp:Label ID="Label1" runat="server" Text="Department Number:"></asp:Label><br />
                <asp:TextBox ID="TextBox1" tabindex="1" runat="server"></asp:TextBox><br />
                <asp:Label ID="label18" runat="server" Text="Example: 153000" Font-Size="Smaller"></asp:Label><br /><br />
                
                <asp:Label ID="Label3" runat="server" Text="Institution OU:"></asp:Label><br />
                <asp:TextBox ID="TextBox3" tabindex="3" runat="server"></asp:TextBox><br />
                <asp:Label ID="label20" runat="server" Text="Example: School or Hospital" Font-Size="Smaller"></asp:Label><br /><br />
                
                <asp:Label ID="Label5" runat="server" Text="Home Directory Location:"></asp:Label><br />
                <asp:TextBox ID="TextBox5" tabindex="5" runat="server"></asp:TextBox><br />
                <asp:Label ID="label22" runat="server" Text="Example: \\csb1\csderm$" Font-Size="Smaller"></asp:Label><br /><br />
                
                <asp:Label ID="Label7" runat="server" Text="Admin Contact Name:"></asp:Label><br />
                <asp:TextBox ID="TextBox7" tabindex="7" runat="server"></asp:TextBox><br /><br />
                
                <asp:Label ID="Label9" runat="server" Text="Admin Contact Email:"></asp:Label><br />
                <asp:TextBox ID="TextBox9" tabindex="9" runat="server"></asp:TextBox><br /><br />    
                <div class="left-container">LEFT</div>   
            </div> <!-- end #left-->    
        </div> <!-- end class main-container -->   
        
        <div class="bottom-container">            
                <div class="label-container"> 
                    <asp:Label ID="lblResults" runat="server"></asp:Label>                
                </div> <!-- end class label-container -->
                                
                <div class="image-container"> 
                    <asp:Image ID="imgCheckMark" runat="server" 
                        ImageUrl="~/images/checkmark_Bold_Brush_Green.png" Height="30px"/>
                    <asp:Image ID="imgRedX" runat="server" ImageUrl="~/images/red_X.jpg" Height="30px"/>
                </div><!-- end class image container --> 			
            
                <div class="button-container">
                    <asp:Button ID="Clear" tabindex="-1" runat="server" Text="Clear" />
                    <asp:Button ID="Submit" tabindex="-1" runat="server" Text="Submit" />
                    <asp:Button ID="View" tabindex="-1" runat="server" Text="View File" />
                </div><!-- end button-container -->                
        </div> <!-- end class bottom-container -->          
            
        
   </div><!-- end #content -->
 
	        <div id="footer">
                <asp:Label ID="Label17" runat="server" Text="  Requested by:  "></asp:Label>
                <asp:Label ID="Label16" runat="server"></asp:Label><br /><br /><br />
	        </div> 
</div><!-- end #wrapper -->	        
	     <div class="gridview-container">
	     
	     <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                 ConnectionString="<%$ ConnectionStrings:MyConnection2 %>" 
                 SelectCommand="SELECT * FROM [Automated_ZM_Dept_Request]">
             </asp:SqlDataSource>
	     
	        <asp:GridView ID="GridView1" runat="server" Wrap="False" AllowSorting="True" ForeColor="Black" ShowFooter="True" CellPadding="4" 
                BackColor="White" BorderWidth="1px" BorderStyle="None" BorderColor="#CCCCCC" Height="135px">
                <HeaderStyle Font-Bold="true" Wrap="false" ForeColor="White" BackColor="#333333" /> 
                <FooterStyle Font-Bold="true" Wrap="false" ForeColor="White" BackColor="#333333" />                
                <AlternatingRowStyle Font-Bold="True" Wrap="False" ForeColor="black" BackColor="#CCCC99"></AlternatingRowStyle>
				<Columns>
                     <asp:CommandField ShowSelectButton="True" />
                     <asp:BoundField HeaderText="Dept ID" DataField="Dept ID" SortExpression="Dept ID" />
                     <asp:BoundField HeaderText="Dept" DataField="Dept" SortExpression="Dept" />
                     <asp:BoundField HeaderText="Inst OU" DataField="Inst OU" SortExpression="[Inst OU]" />
                     <asp:BoundField HeaderText="Home Dir" DataField="Home Dir" SortExpression="[Home Dir]" />
                     <asp:BoundField HeaderText="Groups" DataField="Groups" SortExpression="[Groups]" />
                     <asp:BoundField HeaderText="Contact" DataField="Contact" SortExpression="[Contact]" />
                     <asp:BoundField HeaderText="Phone" DataField="Phone" SortExpression="[Phone]" />
                     <asp:BoundField HeaderText="Email" DataField="Email" SortExpression="[Email]" />
                     <asp:BoundField HeaderText="Zone Mgr" DataField="Zone Mgr" SortExpression="[Zone Mgr]" />
                     <asp:BoundField HeaderText="Submitted" DataField="Submitted" SortExpression="[Submitted]" />
                     <asp:BoundField HeaderText="Requestor" DataField="Requestor" SortExpression="[Requestor]" />                                                   
                 </Columns>
             </asp:GridView>                
		 </div> <!-- end gridview-container --> 
               
    </form>
</body>
</html>
 
aspx.vb
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.DirectoryServices
Imports System.Collections
Imports System.Collections.Specialized
 
Namespace add_account_excel
 
    Partial Public Class _Default
        Inherits System.Web.UI.Page
        Dim strUser As String
        Dim strDate As String
        Dim DS As System.Data.DataSet
 
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            lblResults.Visible = False
            imgCheckMark.Visible = False
            imgRedX.Visible = False
            strUser = (Request.ServerVariables("AUTH_USER"))
 
            If InStr(strUser, "domain\") Then
                strUser = Replace(strUser, "domain\", "")
            End If
 
            If InStr(strUser, "domain\") Then
                strUser = Replace(strUser, "domain\", "")
            End If
 
            Label16.Text = strUser
 
            Call getDatafromfile()
        End Sub
 
        Sub getDatafromfile()
            Dim sConn As SqlConnection
            Dim sComm As SqlCommand
            Dim sAdapt As SqlDataAdapter
 
            sConn = New Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("MyConnection").ConnectionString)
            sComm = New SqlCommand("select * from Automated_ZM_Dept_Request", sConn)
            sAdapt = New SqlDataAdapter(sComm)
            sConn.Open()
 
            DS = New DataSet
            sAdapt.Fill(DS)
            GridView1.DataSource = DS
            GridView1.DataBind()
            sConn.Close()
 
        End Sub
 
        Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit.Click
            Dim strDate As String
            strDate = DateString & "@" & TimeString
 
            If TextBox1.Text = "" Then
                lblResults.Visible = True
                imgCheckMark.Visible = False
                imgRedX.Visible = True
                lblResults.Text = "Please enter 'Department ID'"
            ElseIf TextBox2.Text = "" Then
                lblResults.Visible = True
                imgCheckMark.Visible = False
                imgRedX.Visible = True
                lblResults.Text = "Please enter 'Department Name'"
            ElseIf TextBox3.Text = "" Then
                lblResults.Visible = True
                imgCheckMark.Visible = False
                imgRedX.Visible = True
                lblResults.Text = "Please enter 'Institution OU'"
            ElseIf TextBox4.Text = "" Then
                lblResults.Visible = True
                imgCheckMark.Visible = False
                imgRedX.Visible = True
                lblResults.Text = "Please enter 'Department OU'"
            ElseIf TextBox5.Text = "" Then
                lblResults.Visible = True
                imgCheckMark.Visible = False
                imgRedX.Visible = True
                lblResults.Text = "Please enter 'Home Directory Location'"
            ElseIf TextBox6.Text = "" Then
                lblResults.Visible = True
                imgCheckMark.Visible = False
                imgRedX.Visible = True
                lblResults.Text = "Please enter 'Groups'"
            ElseIf TextBox7.Text = "" Then
                lblResults.Visible = True
                imgCheckMark.Visible = False
                imgRedX.Visible = True
                lblResults.Text = "Please enter 'Admin Contact'"
            ElseIf TextBox8.Text = "" Then
                lblResults.Visible = True
                imgCheckMark.Visible = False
                imgRedX.Visible = True
                lblResults.Text = "Please enter 'Phone Number'"
            ElseIf TextBox9.Text = "" Then
                lblResults.Visible = True
                imgCheckMark.Visible = False
                imgRedX.Visible = True
                lblResults.Text = "Please enter 'Contact Email'"
            ElseIf TextBox10.Text = "" Then
                lblResults.Visible = True
                imgCheckMark.Visible = False
                imgRedX.Visible = True
                lblResults.Text = "Please enter 'Zone Manager'"
            Else
                lblResults.Visible = True
                imgCheckMark.Visible = True
                imgRedX.Visible = False
                lblResults.Text = "New Department Request Submitted"
                Call Add_SQL()
            End If
 
        End Sub
 
        Public Sub Add_SQL()
 
            Dim sConn As Data.SqlClient.SqlConnection
            Dim sComm As Data.SqlClient.SqlCommand
            Dim sAdapt As Data.SqlClient.SqlDataAdapter
 
            sConn = New Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("MyConnection").ConnectionString)
            sComm = New Data.SqlClient.SqlCommand("INSERT INTO Automated_ZM_Dept_Request ([Dept ID], Dept, [Dept OU], [Inst OU], [Home Dir], Groups, Contact, Phone, Email, [Zone Mgr], Submitted, Requestor) VALUES ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "','" & TextBox9.Text & "','" & TextBox10.Text & "','" & strDate & "','" & strUser & "')", sConn)
            sAdapt = New Data.SqlClient.SqlDataAdapter(sComm)
            sConn.Open()
            sComm.ExecuteNonQuery()
            sConn.Close()
 
            clrFields()
            getDatafromfile()
        End Sub
 
        Sub clrFields()
            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox3.Text = ""
            TextBox4.Text = ""
            TextBox5.Text = ""
            TextBox6.Text = ""
            TextBox7.Text = ""
            TextBox8.Text = ""
            TextBox9.Text = ""
            TextBox10.Text = ""
            lblResults.Visible = True
            imgCheckMark.Visible = True
            imgRedX.Visible = False
            lblResults.Text = "New Department Request Submitted"
 
        End Sub
 
        Protected Sub Clear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Clear.Click
            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox3.Text = ""
            TextBox4.Text = ""
            TextBox5.Text = ""
            TextBox6.Text = ""
            TextBox7.Text = ""
            TextBox8.Text = ""
            TextBox9.Text = ""
            TextBox10.Text = ""
            lblResults.Visible = False
            imgCheckMark.Visible = False
            imgRedX.Visible = False
 
        End Sub
 
        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles View.Click
            lblResults.Text = Nothing
            getDatafromfile()
        End Sub
 
        Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
 
        End Sub
    End Class
End Namespace

Open in new window

Avatar of spprivate
spprivate
Flag of United States of America image

Check for Page.Ispostback not equal to true before calling the getdata function
Otherwise everytime you load this page or postback it will get data which is the reason you see twice
Avatar of JB4375

ASKER

Ok, I got the same result either way. Below is what I added to Handles Me.Load

If Not IsPostBack Then
Call getDatafromfile()
End If
Avatar of Bob Learned
Yoooouuuuu rannnnggg?
Avatar of JB4375

ASKER

Yes... I've got the gridview displaying the data. If I remove the statement in the me.load area. I'm left with only the form, and the grid is gone.
If I leave the statements in me.load. or click on view file, it displays displays Dept ID through Requestor, and then repeats it a second time on the same rows.
Originally the me.load displayed everything OK, but I needed to add the gridview because once I get this problem taken care of, I need to be able to edit and sort.
Thanks.
OK, so you are talking about Page_Load:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            lblResults.Visible = False
            imgCheckMark.Visible = False
            imgRedX.Visible = False
            strUser = (Request.ServerVariables("AUTH_USER"))
 
            If InStr(strUser, "domain\") Then
                strUser = Replace(strUser, "domain\", "")
            End If
 
            If InStr(strUser, "domain\") Then
                strUser = Replace(strUser, "domain\", "")
            End If
 
            Label16.Text = strUser
 
            Call getDatafromfile()
        End Sub

Which statement are you "removing"? Guess = Call getDatafromfile()
Avatar of JB4375

ASKER

That is correct.... and SPPRIVATE suggested that I setup it up to call only if it's not a post back. I tried it with the following condition, but no luck.
If Not IsPostBack Then
Call getDatafromfile()
End If  
It's interesting that gridview has so many built in features that don't require additional coding like datagrid before it, but I'm having no luck with most of them. It's kinda frustrating to say the least.
 
You have a lot going on there, so I need to make sure that I get all the details.

1) I see an SqlDataSource, but I don't see where you are using it.

2) The check for Not IsPostBack should work, unless you have turned off the view state for the grid or the page.

3) If you have an SqlDataSource with the GridView, then the two controls work with each other to take care of a lot of things, like displaying data, sorting, paging, ...

4) Are you storing anything, like a DataSet, DataTable, ... in a Session variable?
Avatar of JB4375

ASKER

OK... if it helps.... on the default. asp:   You can ignore everything in the Header container, and the wrapper. That's just the form, and it works fine to submit the data to the SQL file. In the gridview container is gridview1, and it's SQL datasource.
On aspx.vb:  You can ignore Protected Sub...handles submit.click; Sub Clear fields, Protected Sub....Handles Clear.Click; this all related to the form again e.g. presentation, insuring all fields are completed with data.
1. SQL connection strings are in the web.config. They test good. (Assuming that's what you were asking.
2. Not sure about the viewstate. I haven't, to my knowledge, turned anything off.
3. I do have a SQLDataSource with the gridview.
4. I'm not storing anything, to the best of my knowledge, in a Session Variable.
I'm resubmitting the code below. I've left out everything pertaining to the form so you can just see the actual part that partains to the grid.
Thanks.
 
 
 

default.aspx:
 
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Theme="Theme1" Inherits="add_account_excel._Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Zone Manager New Department Request Form </title>
    <link href="default.css" rel="stylesheet" type="text/css" />
    <meta content="True" name="vs_snapToGrid" />
	<meta content="True" name="vs_showGrid" /><meta content="JavaScript" name="vs_defaultClientScript" />
</head>
<body>
    <form id="form1" method="post" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
 
<div class="gridview-container">
	   <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                 ConnectionString="<%$ ConnectionStrings:MyConnection2 %>" 
                 SelectCommand="SELECT * FROM [Automated_ZM_Dept_Request]">
             </asp:SqlDataSource>
             	     
	        <asp:GridView ID="GridView1" runat="server" Wrap="False" ForeColor="Black" ShowFooter="True" CellPadding="4" 
                BackColor="White" BorderWidth="1px" BorderStyle="None" BorderColor="#CCCCCC" Height="135px" DataKeyNames = "Dept ID" AllowSorting="True">
                <HeaderStyle Font-Bold="true" Wrap="false" ForeColor="White" BackColor="#333333" /> 
                <FooterStyle Font-Bold="true" Wrap="false" ForeColor="White" BackColor="#333333" />                
                <AlternatingRowStyle Font-Bold="True" Wrap="False" ForeColor="black" BackColor="#CCCC99"></AlternatingRowStyle>
				<Columns>
                     <asp:CommandField ShowSelectButton="True" />
                     <asp:BoundField HeaderText="Dept ID" DataField="Dept ID" SortExpression="Dept ID" />
                     <asp:BoundField HeaderText="Dept" DataField="Dept" SortExpression="Dept" />
                     <asp:BoundField HeaderText="Inst OU" DataField="Inst OU" SortExpression="Inst OU" />
                     <asp:BoundField HeaderText="Home Dir" DataField="Home Dir" SortExpression="Home Dir" />
                     <asp:BoundField HeaderText="Groups" DataField="Groups" SortExpression="Groups" />
                     <asp:BoundField HeaderText="Contact" DataField="Contact" SortExpression="Contact" />
                     <asp:BoundField HeaderText="Phone" DataField="Phone" SortExpression="Phone" />
                     <asp:BoundField HeaderText="Email" DataField="Email" SortExpression="Email" />
                     <asp:BoundField HeaderText="Zone Mgr" DataField="Zone Mgr" SortExpression="Zone Mgr" />
                     <asp:BoundField HeaderText="Submitted" DataField="Submitted" SortExpression="Submitter" />
                     <asp:BoundField HeaderText="Requestor" DataField="Requestor" SortExpression="Requestor" />                                                   
                 </Columns>
             </asp:GridView>                          
		 </div> <!-- end gridview-container -->
   </form>
</body>
</html>
 
aspx.vb:
 
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.DirectoryServices
Imports System.Collections
Imports System.Collections.Specialized
 
Namespace add_account_excel
 
    Partial Public Class _Default
        Inherits System.Web.UI.Page
        Dim strUser As String
        Dim strDate As String
        Dim DS As System.Data.DataSet
 
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            lblResults.Visible = False
            imgCheckMark.Visible = False
            imgRedX.Visible = False
            strUser = (Request.ServerVariables("AUTH_USER"))
 
            If InStr(strUser, "MEDCTR\") Then
                strUser = Replace(strUser, "MEDCTR\", "")
            End If
 
            If InStr(strUser, "medctr\") Then
                strUser = Replace(strUser, "medctr\", "")
            End If
 
            Label16.Text = strUser
 
            If Not IsPostBack Then
                Call getDatafromfile()
            End If
 
        End Sub
 
        Sub getDatafromfile()
            Dim sConn As SqlConnection
            Dim sComm As SqlCommand
            Dim sAdapt As SqlDataAdapter
            sConn = New Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("MyConnection").ConnectionString)
            sComm = New SqlCommand("select * from Automated_ZM_Dept_Request", sConn)
            sAdapt = New SqlDataAdapter(sComm)
            sConn.Open()
            DS = New DataSet
            sAdapt.Fill(DS)
            GridView1.DataSource = DS
            GridView1.DataBind()
            sConn.Close()
        End Sub
 
User enters data and clicks submit, data is verified, and calls the following to enter it to the table:
 
        Public Sub Add_SQL()
 
            Dim sConn As Data.SqlClient.SqlConnection
            Dim sComm As Data.SqlClient.SqlCommand
            Dim sAdapt As Data.SqlClient.SqlDataAdapter
 
            sConn = New Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("MyConnection").ConnectionString)
            sComm = New Data.SqlClient.SqlCommand("INSERT INTO Automated_ZM_Dept_Request ([Dept ID], Dept, [Dept OU], [Inst OU], [Home Dir], Groups, Contact, Phone, Email, [Zone Mgr], Submitted, Requestor) VALUES ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "','" & TextBox9.Text & "','" & TextBox10.Text & "','" & strDate & "','" & strUser & "')", sConn)
            sAdapt = New Data.SqlClient.SqlDataAdapter(sComm)
            sConn.Open()
            sComm.ExecuteNonQuery()
            sConn.Close()
 
            clrFields()
            getDatafromfile()
        End Sub

Open in new window

You have an SqlDataSource, but since you didn't set DataSourceID = "SqlDataSource1", then you are using the code in the 'getDatafromfile' method to fill the DataSet, so the SqlDataSource is ignored.

Can you attach a .png screen shot of how the page is rendered incorrectly, please?
Avatar of JB4375

ASKER

Sorry for the delay.
Thanks.

Example2.png
Avatar of JB4375

ASKER

Quote: You have an SqlDataSource, but since you didn't set DataSourceID = "SqlDataSource1", then you are using the code in the 'getDatafromfile' method to fill the DataSet, so the SqlDataSource is ignored.
I took a look at the gridview portion of my code, and realized you were right. Then I cross checked my Professional ASP.Net book, and sure enough, they have the statement that you recommended as well. I added the declaration: DataSourceID = "SqlDataSource1" to gridview1.
Then I get the following error: Both DataSource and DataSourceID are defined on 'GridView1'.  Remove one definition. I checked the book again, and it's in both places. What the hell??
If you are going to use an SqlDataSource, then you can only set the DataSourceID property, and not the DataSource property.  If the book shows both, then you have found an error in the book (which is indicated by that error).  
Avatar of JB4375

ASKER

OK.... I'm at a loss. Can you elaborate where the change you suggested needs to be made? Also, do you think this is why it's listing the data twice?
Suggestion:

Use the SqlDataSource--set the GridView.DataSourceId="SqlDataSource1", and don't use 'getDatafromfile'.
Avatar of JB4375

ASKER

Ok... I'm still missing something because this is where I was on the original post. Without the getDatafromfile portion the only thing that displays is the form. With it, it displays twice.
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JB4375

ASKER

Check this out.... I found a datagrid example for beginners on aspnet101.com. Originally I had the following code:
  <asp:GridView ID="GridView1" runat="server" Wrap="False" ForeColor="Black" ShowFooter="True" CellPadding="4"
                BackColor="White" BorderWidth="1px" BorderStyle="None" BorderColor="#CCCCCC" Height="135px" AllowSorting="True">
                <HeaderStyle Font-Bold="true" Wrap="false" ForeColor="White" BackColor="#333333" />
                <FooterStyle Font-Bold="true" Wrap="false" ForeColor="White" BackColor="#333333" />                
                <AlternatingRowStyle Font-Bold="True" Wrap="False" ForeColor="black" BackColor="#CCCC99"></AlternatingRowStyle>
    <Columns>
                     <asp:CommandField ShowSelectButton="True" />
                     <asp:BoundField HeaderText="Dept ID" DataField="Dept ID" SortExpression="Dept ID" />
                     <asp:BoundField HeaderText="Dept" DataField="Dept" SortExpression="Dept" />
                     <asp:BoundField HeaderText="Inst OU" DataField="Inst OU" SortExpression="Inst OU" />
                     <asp:BoundField HeaderText="Home Dir" DataField="Home Dir" SortExpression="Home Dir" />
                     <asp:BoundField HeaderText="Groups" DataField="Groups" SortExpression="Groups" />
                     <asp:BoundField HeaderText="Contact" DataField="Contact" SortExpression="Contact" />
                     <asp:BoundField HeaderText="Phone" DataField="Phone" SortExpression="Phone" />
                     <asp:BoundField HeaderText="Email" DataField="Email" SortExpression="Email" />
                     <asp:BoundField HeaderText="Zone Mgr" DataField="Zone Mgr" SortExpression="Zone Mgr" />
                     <asp:BoundField HeaderText="Submitted" DataField="Submitted" SortExpression="Submitter" />
                     <asp:BoundField HeaderText="Requestor" DataField="Requestor" SortExpression="Requestor" />                                                  
                 </Columns>
             </asp:GridView>
             
      <asp:SqlDataSource ID="SqlDataSource1" runat="server"
             SelectCommand="SELECT * FROM [Automated_ZM_Dept_Request]"
                ConnectionString="<%$ ConnectionStrings:MyConnection2 %>"                  
                DataSourceMode="DataSet">
             </asp:SqlDataSource>  
I replaced it with:
 
<div class="gridview-container">                     ******Data Source Below*********
<asp:GridView ID="GridView1" DataSourceID="SqlDataSource1" runat="server" />


<asp:SqlDataSource ID="SqlDataSource1" runat="server"  <-------***Data Source here***
SelectCommand="SELECT * FROM [Automated_ZM_Dept_Request]"
ConnectionString="<%$ ConnectionStrings:MyConnection2 %>"
DataSourceMode="DataSet">
</asp:SqlDataSource>
</div> <!-- end gridview-container -->
Now it displays once, I don't have anything on aspx.vb side calling it as you suggested, but I have two datasource declarations and it's not erroring out. LOL. Any thoughts about this?
 
It looks like you deleted all the columns for the GridView, and went with auto-generated columns.  I don't see two data source declarations.
Avatar of JB4375

ASKER

Ok... I had SqlDataSource ID="SqlDataSource1" listed for the connection string portion. When I added it to the gridview portion, as indictated above I started getting errors.
Anyway, it's working, and  I'm gradually adding back to the grid code in order to display with color etc. I REALLY REALLY appreiciate all of your help. I'd give you 10K points if it would let me.
Thanks so much!!
Avatar of JB4375

ASKER

Above and beyond, over the top, assistance. Thanks again!!