Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > GridView is making two of each column

Reply
Thread Tools

GridView is making two of each column

 
 
Nathan Sokalski
Guest
Posts: n/a
 
      11-14-2007
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
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.nathansokalski.com/


 
Reply With Quote
 
 
 
 
Nathan Sokalski
Guest
Posts: n/a
 
      11-14-2007
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
(E-Mail Removed)
http://www.nathansokalski.com/

"Barrie Wilson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> don't forget the last attribute here:
>
> <aspataGrid ID="DefaultGrid" Runat="server" AutoGenerateColumns=False>
>
>
>
> "Nathan Sokalski" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>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
>> (E-Mail Removed)
>> http://www.nathansokalski.com/
>>

>
>



 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      11-18-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
> (E-Mail Removed)
> http://www.nathansokalski.com/
>
> "Barrie Wilson" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>
>> don't forget the last attribute here:
>>
>> <aspataGrid ID="DefaultGrid" Runat="server" AutoGenerateColumns=False>
>>
>>
>>
>> "Nathan Sokalski" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>>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
>>> (E-Mail Removed)
>>> http://www.nathansokalski.com/
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making customValidator for a checkbox column in a gridview Andy B. ASP .Net 1 02-12-2009 01:17 PM
gridview column values to another page via gridview hyperlink column Keith G Hicks ASP .Net 3 02-18-2008 06:17 AM
GridView is making two of each column Nathan Sokalski ASP .Net 3 11-18-2007 03:36 PM
How to hide a GridView column when the column's Visible property does not support databinding? Keithb ASP .Net 2 10-27-2006 05:02 AM
Datagrid - each item having two headers one displayed by row another by column Krishna ASP .Net 0 07-13-2006 07:36 AM



Advertisments