473,320 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 1910

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 for any suggestion! -- WWW:...
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 other in my gridview on editing. Any assistance...
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 all set to the default. But after paging to...
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 one column has property "visible" set to...
0
by: =?Utf-8?B?RWR3YXJkSA==?= | last post by:
In Gridview I have column representing Thumbnail image which works fine.: <asp:ImageField DataImageUrlField="PicFile1" DataImageUrlFormatString="Images/A009/Thumbs/{0}"> </asp:ImageField> I...
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 nothing from column A appears in column B and...
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 with about 500 records in the table. Col1...
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 alignment below >human ACCT >mouse ACCT...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.