472,331 Members | 1,390 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 software developers and data experts.

GridView is making two of each column

I have a GridView control with three columns, all BoundField columns. They
all have a HeaderText and DataField property set, and the third one has a
DataFormatString property as well. When I run my code, the GridView displays
two sets of columns. The first set looks exactly as I would expect. The
second set, which should not be there anyway, uses the DataField as the
header and does not apply the DataFormatString for the third column. What is
going on here? Here is my GridView control:

<asp:GridView ID="grdGifts" runat="server" PageSize="15"
PagerSettings-Mode="NextPrevious" PagerSettings-NextPageText="Next 15
Products" PagerSettings-Position="Bottom"
PagerSettings-PreviousPageText="Previous 15 Products"
EnableSortingAndPagingCallbacks="true" AllowPaging="true"
AllowSorting="true">
<Columns>
<asp:BoundField HeaderText="Products" DataField="prodname"/>
<asp:BoundField HeaderText="Brand" DataField="brandname"/>
<asp:BoundField HeaderText="Action" DataField="prodid"
DataFormatString="[&nbsp;<a
href='edit_product.asp?prodid={0}'>Edit</a>&nbsp;/&nbsp;<a
href='delete_product.asp?prodid={0}'>Delete</a>&nbsp;]"/>
</Columns>
</asp:GridView>

The Load event for the GridView is as follows:

Private Sub grdGifts_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles grdGifts.Load
Dim myconnection As New
SqlConnection(System.Configuration.ConfigurationMa nager.AppSettings("connectionstring"))
Dim gifts As New DataTable
Dim giftadapter As New SqlDataAdapter("SELECT
products.prodname,brands.brandname,products.prodid FROM products INNER JOIN
brands ON prodbrand=brandid", myconnection)
giftadapter.Fill(gifts)
Me.grdGifts.DataSource = gifts
Me.grdGifts.DataBind()
End Sub

If anybody has any idea why this is happening, I would appreciate the help.
Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Nov 14 '07 #1
3 1838

don't forget the last attribute here:

<asp:DataGrid ID="DefaultGrid" Runat="server" AutoGenerateColumns=False>

"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:e7**************@TK2MSFTNGP04.phx.gbl...
>I have a GridView control with three columns, all BoundField columns. They
all have a HeaderText and DataField property set, and the third one has a
DataFormatString property as well. When I run my code, the GridView
displays two sets of columns. The first set looks exactly as I would
expect. The second set, which should not be there anyway, uses the
DataField as the header and does not apply the DataFormatString for the
third column. What is going on here? Here is my GridView control:

<asp:GridView ID="grdGifts" runat="server" PageSize="15"
PagerSettings-Mode="NextPrevious" PagerSettings-NextPageText="Next 15
Products" PagerSettings-Position="Bottom"
PagerSettings-PreviousPageText="Previous 15 Products"
EnableSortingAndPagingCallbacks="true" AllowPaging="true"
AllowSorting="true">
<Columns>
<asp:BoundField HeaderText="Products" DataField="prodname"/>
<asp:BoundField HeaderText="Brand" DataField="brandname"/>
<asp:BoundField HeaderText="Action" DataField="prodid"
DataFormatString="[&nbsp;<a
href='edit_product.asp?prodid={0}'>Edit</a>&nbsp;/&nbsp;<a
href='delete_product.asp?prodid={0}'>Delete</a>&nbsp;]"/>
</Columns>
</asp:GridView>

The Load event for the GridView is as follows:

Private Sub grdGifts_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles grdGifts.Load
Dim myconnection As New
SqlConnection(System.Configuration.ConfigurationMa nager.AppSettings("connectionstring"))
Dim gifts As New DataTable
Dim giftadapter As New SqlDataAdapter("SELECT
products.prodname,brands.brandname,products.prodid FROM products INNER
JOIN brands ON prodbrand=brandid", myconnection)
giftadapter.Fill(gifts)
Me.grdGifts.DataSource = gifts
Me.grdGifts.DataBind()
End Sub

If anybody has any idea why this is happening, I would appreciate the
help. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 14 '07 #2
My sorting also isn't working. I looked at the generated code, and it looks
correct. Here is the code for my GridView and the databinding:

<asp:GridView ID="grdGifts" runat="server" PageSize="15"
PagerSettings-Mode="NextPrevious" PagerSettings-NextPageText="Next 15
Products" PagerSettings-Position="Bottom"
PagerSettings-PreviousPageText="Previous 15 Products"
EnableSortingAndPagingCallbacks="true" AllowPaging="true"
AllowSorting="true" AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="Products" DataField="prodname"
SortExpression="products.prodname"/>
<asp:BoundField HeaderText="Brand" DataField="brandname"
SortExpression="brands.brandname"/>
<asp:BoundField HeaderText="Action" DataField="prodid"
DataFormatString="[&nbsp;<a
href='edit_product.asp?prodid={0}'>Edit</a>&nbsp;/&nbsp;<a
href='delete_product.asp?prodid={0}'>Delete</a>&nbsp;]"/>
</Columns>
</asp:GridView>

Private Sub grdGifts_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles grdGifts.Load
Dim myconnection As New
SqlConnection(System.Configuration.ConfigurationMa nager.AppSettings("connectionstring"))
Dim gifts As New DataTable
Dim giftadapter As New SqlDataAdapter("SELECT
products.prodname,brands.brandname,products.prodid FROM products INNER JOIN
brands ON products.prodbrand=brands.brandid", myconnection)
giftadapter.Fill(gifts)
Me.grdGifts.DataSource = gifts
Me.grdGifts.DataBind()
End Sub

Am I also forgetting some simple little thing for the sorting? I have the
AllowSorting="true" and the SortExpression property for the columns that I
need to be sortable. Is there something else I need? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Barrie Wilson" <bw*****@nowhere.comwrote in message
news:13*************@corp.supernews.com...
>
don't forget the last attribute here:

<asp:DataGrid ID="DefaultGrid" Runat="server" AutoGenerateColumns=False>

"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:e7**************@TK2MSFTNGP04.phx.gbl...
>>I have a GridView control with three columns, all BoundField columns. They
all have a HeaderText and DataField property set, and the third one has a
DataFormatString property as well. When I run my code, the GridView
displays two sets of columns. The first set looks exactly as I would
expect. The second set, which should not be there anyway, uses the
DataField as the header and does not apply the DataFormatString for the
third column. What is going on here? Here is my GridView control:

<asp:GridView ID="grdGifts" runat="server" PageSize="15"
PagerSettings-Mode="NextPrevious" PagerSettings-NextPageText="Next 15
Products" PagerSettings-Position="Bottom"
PagerSettings-PreviousPageText="Previous 15 Products"
EnableSortingAndPagingCallbacks="true" AllowPaging="true"
AllowSorting="true">
<Columns>
<asp:BoundField HeaderText="Products" DataField="prodname"/>
<asp:BoundField HeaderText="Brand" DataField="brandname"/>
<asp:BoundField HeaderText="Action" DataField="prodid"
DataFormatString="[&nbsp;<a
href='edit_product.asp?prodid={0}'>Edit</a>&nbsp;/&nbsp;<a
href='delete_product.asp?prodid={0}'>Delete</a>&nbsp;]"/>
</Columns>
</asp:GridView>

The Load event for the GridView is as follows:

Private Sub grdGifts_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles grdGifts.Load
Dim myconnection As New
SqlConnection(System.Configuration.ConfigurationM anager.AppSettings("connectionstring"))
Dim gifts As New DataTable
Dim giftadapter As New SqlDataAdapter("SELECT
products.prodname,brands.brandname,products.prodi d FROM products INNER
JOIN brands ON prodbrand=brandid", myconnection)
giftadapter.Fill(gifts)
Me.grdGifts.DataSource = gifts
Me.grdGifts.DataBind()
End Sub

If anybody has any idea why this is happening, I would appreciate the
help. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/


Nov 14 '07 #3
Code in Page_Load would need to be inside If Not Page.IsPostBack Then check
so that it won't prevent postback events (such as Sorting event) from
working.
--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:ef**************@TK2MSFTNGP05.phx.gbl...
My sorting also isn't working. I looked at the generated code, and it
looks correct. Here is the code for my GridView and the databinding:

<asp:GridView ID="grdGifts" runat="server" PageSize="15"
PagerSettings-Mode="NextPrevious" PagerSettings-NextPageText="Next 15
Products" PagerSettings-Position="Bottom"
PagerSettings-PreviousPageText="Previous 15 Products"
EnableSortingAndPagingCallbacks="true" AllowPaging="true"
AllowSorting="true" AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="Products" DataField="prodname"
SortExpression="products.prodname"/>
<asp:BoundField HeaderText="Brand" DataField="brandname"
SortExpression="brands.brandname"/>
<asp:BoundField HeaderText="Action" DataField="prodid"
DataFormatString="[&nbsp;<a
href='edit_product.asp?prodid={0}'>Edit</a>&nbsp;/&nbsp;<a
href='delete_product.asp?prodid={0}'>Delete</a>&nbsp;]"/>
</Columns>
</asp:GridView>

Private Sub grdGifts_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles grdGifts.Load
Dim myconnection As New
SqlConnection(System.Configuration.ConfigurationMa nager.AppSettings("connectionstring"))
Dim gifts As New DataTable
Dim giftadapter As New SqlDataAdapter("SELECT
products.prodname,brands.brandname,products.prodid FROM products INNER
JOIN brands ON products.prodbrand=brands.brandid", myconnection)
giftadapter.Fill(gifts)
Me.grdGifts.DataSource = gifts
Me.grdGifts.DataBind()
End Sub

Am I also forgetting some simple little thing for the sorting? I have the
AllowSorting="true" and the SortExpression property for the columns that I
need to be sortable. Is there something else I need? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Barrie Wilson" <bw*****@nowhere.comwrote in message
news:13*************@corp.supernews.com...
>>
don't forget the last attribute here:

<asp:DataGrid ID="DefaultGrid" Runat="server" AutoGenerateColumns=False>

"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:e7**************@TK2MSFTNGP04.phx.gbl...
>>>I have a GridView control with three columns, all BoundField columns.
They all have a HeaderText and DataField property set, and the third one
has a DataFormatString property as well. When I run my code, the GridView
displays two sets of columns. The first set looks exactly as I would
expect. The second set, which should not be there anyway, uses the
DataField as the header and does not apply the DataFormatString for the
third column. What is going on here? Here is my GridView control:

<asp:GridView ID="grdGifts" runat="server" PageSize="15"
PagerSettings-Mode="NextPrevious" PagerSettings-NextPageText="Next 15
Products" PagerSettings-Position="Bottom"
PagerSettings-PreviousPageText="Previous 15 Products"
EnableSortingAndPagingCallbacks="true" AllowPaging="true"
AllowSorting="true">
<Columns>
<asp:BoundField HeaderText="Products" DataField="prodname"/>
<asp:BoundField HeaderText="Brand" DataField="brandname"/>
<asp:BoundField HeaderText="Action" DataField="prodid"
DataFormatString="[&nbsp;<a
href='edit_product.asp?prodid={0}'>Edit</a>&nbsp;/&nbsp;<a
href='delete_product.asp?prodid={0}'>Delete</a>&nbsp;]"/>
</Columns>
</asp:GridView>

The Load event for the GridView is as follows:

Private Sub grdGifts_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles grdGifts.Load
Dim myconnection As New
SqlConnection(System.Configuration.Configuration Manager.AppSettings("connectionstring"))
Dim gifts As New DataTable
Dim giftadapter As New SqlDataAdapter("SELECT
products.prodname,brands.brandname,products.prod id FROM products INNER
JOIN brands ON prodbrand=brandid", myconnection)
giftadapter.Fill(gifts)
Me.grdGifts.DataSource = gifts
Me.grdGifts.DataBind()
End Sub

If anybody has any idea why this is happening, I would appreciate the
help. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/



Nov 18 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Hardy Wang | last post by:
Hi all, I am just wandering, is it possible to programmatically detect each column's data type of SalDataReader, DataSet.Tables, DataTable? Thanks...
0
by: Mike P | last post by:
How do you validate seperate controls in a gridview against each other? I have several controls that I need to compare the values of against each...
4
by: Chuck | last post by:
I'm setting the column with for a gridview (25+- columns) and have paging turned on. When the gridview is first displayed, the column widths are...
1
by: shema | last post by:
Hi, I'm working in visual studio 2005 on web site application and my database is microsoft sql server 2005. I need to update my GridView while...
0
by: =?Utf-8?B?RWR3YXJkSA==?= | last post by:
In Gridview I have column representing Thumbnail image which works fine.: <asp:ImageField DataImageUrlField="PicFile1"...
1
watertraveller
by: watertraveller | last post by:
Hi all. My ultimate goal is to return two columns, where no single value appears anywhere twice. This means that not only do I want to check that...
1
akashazad
by: akashazad | last post by:
Hi All Pl some body tell me is it possible to have a datagridView in which each column can have diff no of rows in it?
20
by: PokerRebel | last post by:
I am new to MS Access and was wondering how do I code the following using vba and looping each column in the table. I have a table with 6 columns...
7
by: CCGG26 | last post by:
...hey guys.. how can you write aprogram that prints the number of A's in each column of a multiple sequence alignment. For example for the multiple...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.