Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > GridView Sorting Problem

Reply
Thread Tools

GridView Sorting Problem

 
 
GaryDean
Guest
Posts: n/a
 
      12-16-2008
I have a GridView datasourced by a SQLDataSource with Enable Sorting and
Enable Selection turned on. However I don't like the headings and all of
the columns that come from the SQLDataSource in in the RowDataBound event I
do...
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[billmethod].Visible = false;
e.Row.Cells[dateissued].Visible = false;
e.Row.Cells[receiptamt].Visible = false;
e.Row.Cells[cbmark].Text = "Mark";
e.Row.Cells[viewinvoice].Text = "View Doc";
e.Row.Cells[invoicenumber].Text = "Invoice #";
e.Row.Cells[billtoorganization].Text = "Bill To Company";
e.Row.Cells[createdate].Text = "Created";
e.Row.Cells[billcycle].Text = "Pay Type";
e.Row.Cells[status].Text = "Status";
e.Row.Cells[invamt].Text = "Bill Amt";
e.Row.Cells[amtreceived].Text = "Amt Rec";
e.Row.Cells[orgtype].Text = "Aging";


}

This has apparently nuked my sorting feature because my custom headings are
not underlined and clicking on them does not sort. They are born dead. Now
if I hit the select button on any row, the grid shows the headings from SQL
and the sort feature is restored. It stays restored until the next time
RowDataBound is triggered.

I want to have custom headings and the sort capability. Is this possible
without changing my sql?
Thanks,
Gary


 
Reply With Quote
 
 
 
 
Allen Chen [MSFT]
Guest
Posts: n/a
 
      12-17-2008
Hi Gary,

My Name is Allen Chen. It's my pleasure to work with you on this issue.

From your description, you want to use the auto generated columns of the
GridView and to replace the default header LinkButton with your own custom
one. Is my understanding correct?

If so please try the following code in the RowCreated event hanlder of the
GridView control:

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{ Button b=new Button();
b.Text = "Custom Sort Button!";
b.CommandName="Sort";
b.CommandArgument="theID";//the field you want to sort
e.Row.Cells[0].Controls.Clear();
e.Row.Cells[0].Controls.Add(b);
}
}

Here a new button will replace the default LinkButton on the header of the
first column.

The key point is to set the CommandName and the CommandArgument. The
CommandName is mandatory to be "Sort". It means you want to use this button
to sort GridView. The CommandArgument represents the field you want to
sort. You need to replace it with the real one in your case.

Please have a try and let me know if it works. If you need further
assistance please don't hesitate to let me know.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
http://www.velocityreviews.com/forums/(E-Mail Removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
 
 
 
GaryDean
Guest
Posts: n/a
 
      12-17-2008
Allen:
Thanks for your answer.

Actually my goal was not to replace the whole button although I tested your
code and it did work. My goal was just to put up a more friendly text
header than the one returned by SQL i.e. "Invoice #" instead of
"invoicenumber". But learning from your example prompted me to use the
following two lines of code in the RowDataBound event and this also worked:

LinkButton b =
(LinkButton)e.Row.Cells[invoicenumber].Controls[0];
b.Text = "Friendly Heading";
So, problem solved.
Thanks,
Gary

"Allen Chen [MSFT]" <(E-Mail Removed)> wrote in message
news:703cyT$(E-Mail Removed)...
> Hi Gary,
>
> My Name is Allen Chen. It's my pleasure to work with you on this issue.
>
> From your description, you want to use the auto generated columns of the
> GridView and to replace the default header LinkButton with your own custom
> one. Is my understanding correct?
>
> If so please try the following code in the RowCreated event hanlder of the
> GridView control:
>
> protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
> {
> if (e.Row.RowType == DataControlRowType.Header)
> { Button b=new Button();
> b.Text = "Custom Sort Button!";
> b.CommandName="Sort";
> b.CommandArgument="theID";//the field you want to sort
> e.Row.Cells[0].Controls.Clear();
> e.Row.Cells[0].Controls.Add(b);
> }
> }
>
> Here a new button will replace the default LinkButton on the header of the
> first column.
>
> The key point is to set the CommandName and the CommandArgument. The
> CommandName is mandatory to be "Sort". It means you want to use this
> button
> to sort GridView. The CommandArgument represents the field you want to
> sort. You need to replace it with the real one in your case.
>
> Please have a try and let me know if it works. If you need further
> assistance please don't hesitate to let me know.
>
> Regards,
> Allen Chen
> Microsoft Online Support
>
> Delighting our customers is our #1 priority. We welcome your comments and
> suggestions about how we can improve the support we provide to you. Please
> feel free to let my manager know what you think of the level of service
> provided. You can send feedback directly to my manager at:
> (E-Mail Removed).
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/en-us/subs...#notifications.
>
> Note: MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 2 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions. Issues of this
> nature are best handled working with a dedicated Microsoft Support
> Engineer
> by contacting Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>


 
Reply With Quote
 
Allen Chen [MSFT]
Guest
Posts: n/a
 
      12-18-2008
Hi Gary,

Glad to know this issue has been solved. Have a nice day!

Regards,
Allen Chen
Microsoft Online Support

 
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
Sorting list vs sorting vector boltar2003@boltar.world C++ 2 07-06-2010 09:40 AM
Gridview sorting event - Gridview Datasource always Null .. why??? jobs ASP .Net Web Controls 2 10-24-2006 07:08 AM
fired event Sorting which wasn't handled - sorting and SelectedIndexChanged Jason ASP .Net Web Controls 0 10-04-2006 02:19 PM
GridView Hierarchical View - Gridview in Gridview =?Utf-8?B?bWdvbnphbGVzMw==?= ASP .Net 1 05-09-2006 06:48 PM
sorting by multiple criterias (sub-sorting) Tom Kirchner Perl Misc 3 10-11-2003 05:16 PM



Advertisments