473,856 Members | 1,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
DataFormatStrin g 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 DataFormatStrin g for the third column. What is
going on here? Here is my GridView control:

<asp:GridView ID="grdGifts" runat="server" PageSize="15"
PagerSettings-Mode="NextPrevi ous" PagerSettings-NextPageText="N ext 15
Products" PagerSettings-Position="Botto m"
PagerSettings-PreviousPageTex t="Previous 15 Products"
EnableSortingAn dPagingCallback s="true" AllowPaging="tr ue"
AllowSorting="t rue">
<Columns>
<asp:BoundFie ld HeaderText="Pro ducts" DataField="prod name"/>
<asp:BoundFie ld HeaderText="Bra nd" DataField="bran dname"/>
<asp:BoundFie ld HeaderText="Act ion" DataField="prod id"
DataFormatStrin g="[&nbsp;<a
href='edit_prod uct.asp?prodid= {0}'>Edit</a>&nbsp;/&nbsp;<a
href='delete_pr oduct.asp?prodi d={0}'>Delete</a>&nbsp;]"/>
</Columns>
</asp:GridView>

The Load event for the GridView is as follows:

Private Sub grdGifts_Load(B yVal sender As Object, ByVal e As
System.EventArg s) Handles grdGifts.Load
Dim myconnection As New
SqlConnection(S ystem.Configura tion.Configurat ionManager.AppS ettings("connec tionstring"))
Dim gifts As New DataTable
Dim giftadapter As New SqlDataAdapter( "SELECT
products.prodna me,brands.brand name,products.p rodid FROM products INNER JOIN
brands ON prodbrand=brand id", myconnection)
giftadapter.Fil l(gifts)
Me.grdGifts.Dat aSource = gifts
Me.grdGifts.Dat aBind()
End Sub

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

don't forget the last attribute here:

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

"Nathan Sokalski" <nj********@hot mail.comwrote in message
news:e7******** ******@TK2MSFTN GP04.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
DataFormatStri ng 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 DataFormatStrin g for the
third column. What is going on here? Here is my GridView control:

<asp:GridView ID="grdGifts" runat="server" PageSize="15"
PagerSettings-Mode="NextPrevi ous" PagerSettings-NextPageText="N ext 15
Products" PagerSettings-Position="Botto m"
PagerSettings-PreviousPageTex t="Previous 15 Products"
EnableSortingAn dPagingCallback s="true" AllowPaging="tr ue"
AllowSorting="t rue">
<Columns>
<asp:BoundFie ld HeaderText="Pro ducts" DataField="prod name"/>
<asp:BoundFie ld HeaderText="Bra nd" DataField="bran dname"/>
<asp:BoundFie ld HeaderText="Act ion" DataField="prod id"
DataFormatStrin g="[&nbsp;<a
href='edit_prod uct.asp?prodid= {0}'>Edit</a>&nbsp;/&nbsp;<a
href='delete_pr oduct.asp?prodi d={0}'>Delete</a>&nbsp;]"/>
</Columns>
</asp:GridView>

The Load event for the GridView is as follows:

Private Sub grdGifts_Load(B yVal sender As Object, ByVal e As
System.EventArg s) Handles grdGifts.Load
Dim myconnection As New
SqlConnection(S ystem.Configura tion.Configurat ionManager.AppS ettings("connec tionstring"))
Dim gifts As New DataTable
Dim giftadapter As New SqlDataAdapter( "SELECT
products.prodna me,brands.brand name,products.p rodid FROM products INNER
JOIN brands ON prodbrand=brand id", myconnection)
giftadapter.Fil l(gifts)
Me.grdGifts.Dat aSource = gifts
Me.grdGifts.Dat aBind()
End Sub

If anybody has any idea why this is happening, I would appreciate the
help. Thanks.
--
Nathan Sokalski
nj********@hotm ail.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="NextPrevi ous" PagerSettings-NextPageText="N ext 15
Products" PagerSettings-Position="Botto m"
PagerSettings-PreviousPageTex t="Previous 15 Products"
EnableSortingAn dPagingCallback s="true" AllowPaging="tr ue"
AllowSorting="t rue" AutoGenerateCol umns="false">
<Columns>
<asp:BoundFie ld HeaderText="Pro ducts" DataField="prod name"
SortExpression= "products.prodn ame"/>
<asp:BoundFie ld HeaderText="Bra nd" DataField="bran dname"
SortExpression= "brands.brandna me"/>
<asp:BoundFie ld HeaderText="Act ion" DataField="prod id"
DataFormatStrin g="[&nbsp;<a
href='edit_prod uct.asp?prodid= {0}'>Edit</a>&nbsp;/&nbsp;<a
href='delete_pr oduct.asp?prodi d={0}'>Delete</a>&nbsp;]"/>
</Columns>
</asp:GridView>

Private Sub grdGifts_Load(B yVal sender As Object, ByVal e As
System.EventArg s) Handles grdGifts.Load
Dim myconnection As New
SqlConnection(S ystem.Configura tion.Configurat ionManager.AppS ettings("connec tionstring"))
Dim gifts As New DataTable
Dim giftadapter As New SqlDataAdapter( "SELECT
products.prodna me,brands.brand name,products.p rodid FROM products INNER JOIN
brands ON products.prodbr and=brands.bran did", myconnection)
giftadapter.Fil l(gifts)
Me.grdGifts.Dat aSource = gifts
Me.grdGifts.Dat aBind()
End Sub

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

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

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

"Nathan Sokalski" <nj********@hot mail.comwrote in message
news:e7******** ******@TK2MSFTN GP04.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
DataFormatStr ing 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 DataFormatStrin g for the
third column. What is going on here? Here is my GridView control:

<asp:GridVie w ID="grdGifts" runat="server" PageSize="15"
PagerSetting s-Mode="NextPrevi ous" PagerSettings-NextPageText="N ext 15
Products" PagerSettings-Position="Botto m"
PagerSetting s-PreviousPageTex t="Previous 15 Products"
EnableSortingA ndPagingCallbac ks="true" AllowPaging="tr ue"
AllowSorting=" true">
<Columns>
<asp:BoundFie ld HeaderText="Pro ducts" DataField="prod name"/>
<asp:BoundFie ld HeaderText="Bra nd" DataField="bran dname"/>
<asp:BoundFie ld HeaderText="Act ion" DataField="prod id"
DataFormatStri ng="[&nbsp;<a
href='edit_pro duct.asp?prodid ={0}'>Edit</a>&nbsp;/&nbsp;<a
href='delete_p roduct.asp?prod id={0}'>Delete</a>&nbsp;]"/>
</Columns>
</asp:GridView>

The Load event for the GridView is as follows:

Private Sub grdGifts_Load(B yVal sender As Object, ByVal e As
System.EventAr gs) Handles grdGifts.Load
Dim myconnection As New
SqlConnection( System.Configur ation.Configura tionManager.App Settings("conne ctionstring"))
Dim gifts As New DataTable
Dim giftadapter As New SqlDataAdapter( "SELECT
products.prodn ame,brands.bran dname,products. prodid FROM products INNER
JOIN brands ON prodbrand=brand id", myconnection)
giftadapter.Fil l(gifts)
Me.grdGifts.Dat aSource = gifts
Me.grdGifts.Dat aBind()
End Sub

If anybody has any idea why this is happening, I would appreciate the
help. Thanks.
--
Nathan Sokalski
nj********@hotm ail.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********@hot mail.comwrote in message
news:ef******** ******@TK2MSFTN GP05.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="NextPrevi ous" PagerSettings-NextPageText="N ext 15
Products" PagerSettings-Position="Botto m"
PagerSettings-PreviousPageTex t="Previous 15 Products"
EnableSortingAn dPagingCallback s="true" AllowPaging="tr ue"
AllowSorting="t rue" AutoGenerateCol umns="false">
<Columns>
<asp:BoundFie ld HeaderText="Pro ducts" DataField="prod name"
SortExpression= "products.prodn ame"/>
<asp:BoundFie ld HeaderText="Bra nd" DataField="bran dname"
SortExpression= "brands.brandna me"/>
<asp:BoundFie ld HeaderText="Act ion" DataField="prod id"
DataFormatStrin g="[&nbsp;<a
href='edit_prod uct.asp?prodid= {0}'>Edit</a>&nbsp;/&nbsp;<a
href='delete_pr oduct.asp?prodi d={0}'>Delete</a>&nbsp;]"/>
</Columns>
</asp:GridView>

Private Sub grdGifts_Load(B yVal sender As Object, ByVal e As
System.EventArg s) Handles grdGifts.Load
Dim myconnection As New
SqlConnection(S ystem.Configura tion.Configurat ionManager.AppS ettings("connec tionstring"))
Dim gifts As New DataTable
Dim giftadapter As New SqlDataAdapter( "SELECT
products.prodna me,brands.brand name,products.p rodid FROM products INNER
JOIN brands ON products.prodbr and=brands.bran did", myconnection)
giftadapter.Fil l(gifts)
Me.grdGifts.Dat aSource = gifts
Me.grdGifts.Dat aBind()
End Sub

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

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

<asp:DataGri d ID="DefaultGrid " Runat="server" AutoGenerateCol umns=False>

"Nathan Sokalski" <nj********@hot mail.comwrote in message
news:e7******* *******@TK2MSFT NGP04.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 DataFormatStrin g 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 DataFormatStrin g for the
third column. What is going on here? Here is my GridView control:

<asp:GridVi ew ID="grdGifts" runat="server" PageSize="15"
PagerSettin gs-Mode="NextPrevi ous" PagerSettings-NextPageText="N ext 15
Products" PagerSettings-Position="Botto m"
PagerSettin gs-PreviousPageTex t="Previous 15 Products"
EnableSorting AndPagingCallba cks="true" AllowPaging="tr ue"
AllowSorting= "true">
<Columns>
<asp:BoundFie ld HeaderText="Pro ducts" DataField="prod name"/>
<asp:BoundFie ld HeaderText="Bra nd" DataField="bran dname"/>
<asp:BoundFie ld HeaderText="Act ion" DataField="prod id"
DataFormatStr ing="[&nbsp;<a
href='edit_pr oduct.asp?prodi d={0}'>Edit</a>&nbsp;/&nbsp;<a
href='delete_ product.asp?pro did={0}'>Delete </a>&nbsp;]"/>
</Columns>
</asp:GridView>

The Load event for the GridView is as follows:

Private Sub grdGifts_Load(B yVal sender As Object, ByVal e As
System.EventA rgs) Handles grdGifts.Load
Dim myconnection As New
SqlConnection (System.Configu ration.Configur ationManager.Ap pSettings("conn ectionstring"))
Dim gifts As New DataTable
Dim giftadapter As New SqlDataAdapter( "SELECT
products.prod name,brands.bra ndname,products .prodid FROM products INNER
JOIN brands ON prodbrand=brand id", myconnection)
giftadapter.Fil l(gifts)
Me.grdGifts.Dat aSource = gifts
Me.grdGifts.Dat aBind()
End Sub

If anybody has any idea why this is happening, I would appreciate the
help. Thanks.
--
Nathan Sokalski
nj********@hotm ail.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
10400
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: http://hardywang.1accesshost.com ICQ: 3359839 yours Hardy
0
1020
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 would be really appreciated. *** Sent via Developersdex http://www.developersdex.com ***
4
15449
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 another page, the widths are set as they should be. Going back to page one, the widths are still correct. Not a clue what's going on here!
1
2470
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 "false"(in "edit columns" "visible" is set to "false"). When I click update (same with insert), all the columns that are not shown on the grid are set to NULL, but I need that column to be updated in my database because I'm passing that value from another...
0
1537
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 want the fixed 'A009' to be replaced by Session variable - "ClCode" VB in code-behind I have: iPicFile = ImageString & Session("ClCode") & "/Thumbs/{0}" How can "iPicFile" variable be used in DataImageUrlFormatString?
1
4099
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 vice-versa, but I also don't want the same value appearing twice in A and twice in B. So far I have: --Diff the columns INSERT INTO @Table SELECT One, Two FROM @Column1 a FULL OUTER JOIN @Column2 b
1
1192
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
32296
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 contains a date and time format. Col's 2 - 6 contain random "True" and "False" values in each column. I need to read col2, find the 1st "True" row (call it start time and date), lookup the date and time and add the start date and start time to a new table....
7
1852
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 >cat TCCT >dog ACAT
0
9922
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10702
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10801
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10391
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7935
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7099
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5763
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5963
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4584
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.