CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.faq_frequently_asked_questions Tags:
Item Type: NewsGroup Date Entered: 1/24/2006 6:55:57 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 185 Views: 237 Favorited: 0 Favorite
186 Items, 10 Pages 1 2 3 4 5 6 7 8 9 10 |< << Go >> >|
dba123
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/29/2006 7:08:07 PM

0

I am getting this error when placing the code in my page's code-behind...what's wrong with the original code??


Compiler Error Message: CS0118: 'System.Web.UI.WebControls.SortDirection' is a 'type' but is used like a 'variable'

Source Error:

Line 32:    string newSortDirection = String.Empty;
Line 33: 
Line 34:    switch (SortDirection)
Line 35:    {
Line 36:       case SortDirection.Ascending:

C# Web Developer

When is Microsoft going to get rid of VB.NET!
aspnet_spnt
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/29/2006 7:26:44 PM

0

Hello rayan , this is the code for my grid :

 

public partial class Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

   {

 

        bool boolAdmin = (bool)Session["admin"];

        bool boolWebMaster = (bool)Session["webMaster"];

 

        if (boolAdmin)

        {

            if (!IsPostBack)

            {

                Session["Sorting"] = "ASC";                             

 

                Session["ObjToSortBy"] = "ID"; 

 

                Literal1.Text = "";

                tbSVSearch.Focus();

                string[] strSelection = { "1", "2", "3", "4" };

 

                ddlSelection.DataSource = strSelection;

                ddlSelection.DataBind();

 

                ddlSelection.DataSource = strSelection;

                ddlSelection.DataBind();

 

                string[] strSeach = {"UL", "Date", "Last Name"};

 

                ddlSeach.DataSource = strSeach;

                ddlSeach.DataBind();

 

                if (boolWebMaster)

                {

                    Literal1.Text = @"If you want to edit/delete a log visit the <a href='../webMaster/Default.aspx'> Webmaster</a> part of the site";

                }

            }

        }

        else

        {

            Response.Redirect(@"~\Default.aspx");        }

    }

  

   

    private void dataBind(string strQuery)

    {

        sql mySqlQuery = new sql();

        DataTable dt = mySqlQuery.queryDbReturnDt(strQuery, ref lblResultsError);

      

 

        GridView1.DataSource = dt;

        GridView1.DataBind();

 

        if (dt.Rows.Count == 0)

        {

            GridView1.Visible = false;

            lblResultsError.Text = "Your search did not mach any records. ";

        }

        else

        {

            lblResultsError.Text = "";

            GridView1.Visible = true;

        }

    }

 

   

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)

    {

        GridViewRow row = GridView1.SelectedRow;

 

        Label lblID = row.FindControl("Label1") as Label;

        Label lblUL = row.FindControl("Label2") as Label;

 

        Session["myID"] = lblID.Text; 

        Session["myUl"] = lblUL.Text;           

 

        string strFullname = Session["userFname"].ToString() + " " + Session["userLname"].ToString();

        DateTime today = DateTime.Now;

        string strDateLastViewed = today.ToString();

        sql mySqlQuery = new sql();

        mySqlQuery.queryDbVoid("UPDATE USED_LOG SET LAST_VIEWED_BY = '" + strFullname + "', DATE_LAST_VIEWED = '" + strDateLastViewed + "' WHERE (" + "UL = '" + lblUL.Text + "') AND " + "(ID = '" + lblID.Text + "')", ref lblResultsError);

 

        Response.Redirect("summary.aspx");

    }//END GridView1_SelectedIndexChanged

 

 

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)

    {

        GridView1.PageIndex = e.NewPageIndex;

        dataBind(Session["myQuery"].ToString());

    }

 

 

 

 

<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AllowPaging="True" PageSize="15" OnPageIndexChanging="GridView1_PageIndexChanging" AllowSorting="True" >

      <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />

      <RowStyle BackColor="#EBEBEB" />

      <EditRowStyle BackColor="#7C6F57" />

      <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />

      <PagerStyle BackColor="#0A4A13" ForeColor="White" HorizontalAlign="Center" />

      <HeaderStyle BackColor="#0A4A13" Font-Bold="True" ForeColor="White" />

      <AlternatingRowStyle BackColor="White" />

      <Columns>

          <asp:CommandField ShowSelectButton="True" />

          <asp:TemplateField HeaderText="ID">

              <EditItemTemplate>

                  <asp:Label ID="Label1" runat="server" Text='<%# Eval("ID") %>'></asp:Label>

              </EditItemTemplate>

              <ItemTemplate>

                  <asp:Label ID="Label1" runat="server" Text='<%# Bind("ID") %>'></asp:Label>

              </ItemTemplate>

          </asp:TemplateField>

          <asp:TemplateField HeaderText="UL">

              <EditItemTemplate>

                  <asp:Label ID="Label2" runat="server" Text='<%# Eval("UL") %>'></asp:Label>

              </EditItemTemplate>

              <ItemTemplate>

                  <asp:Label ID="Label2" runat="server" Text='<%# Bind("UL") %>'></asp:Label>

              </ItemTemplate>

          </asp:TemplateField>

          <asp:BoundField DataField="LAST_NAME" HeaderText="Last N" SortExpression = "LAST_NAME" />

          <asp:BoundField DataField="FIRST_NAME" HeaderText="First N"  SortExpression = "FIRST_NAME"/>

          <asp:BoundField DataField="DATE" HeaderText="Date Registered"  SortExpression = "DATE"/>

         

      </Columns>

    </asp:GridView>

 

 

StrongTypes
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/29/2006 7:30:31 PM

0

dba123:
Compiler Error Message: CS0118: 'System.Web.UI.WebControls.SortDirection' is a 'type' but is used like a 'variable'

According to the sample code I provided, it should be sortDirection, not SortDirection.

Ryan


Ryan Olshan
Microsoft MVP, ASP.NET
Blog | Group | Website | Strong Coders Community

How to ask a question
dba123
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/29/2006 7:53:41 PM

0

I can't get it to work.  I'm not sure if I need to or what to put in the SortExpression here:

 

<asp:GridView

    ID="gvPodcasts"

    runat="server"

    AllowPaging="true"

    OnPageIndexChanging="gridView_PageIndexChanging"

    OnSorting="gridView_Sorting"

    PageSize="3"

    AllowSorting="true"

    AutoGenerateColumns = "False"

    BackColor="#FFFCC5"

    BorderColor="Tan"

    BorderWidth="1px"

    CellPadding="2"

    ForeColor="#000000"

    GridLines="None">

     <Columns>

 

        <asp:TemplateField HeaderText="Title" SortExpression="" >    

            <ItemTemplate>

                <asp:Image ID="Image1" ImageUrl="~/images/interact/icon_podcast.gif" runat="server" />

                <asp:HyperLink  ID="hlTitle" runat="server" Text='<%#((Podcast)Container.DataItem).Title %>' NavigateUrl='<%#((Podcast)Container.DataItem).URL %>'  />

                <br /><br />

                <asp:Label ID="lblDescription" runat="server" Text='<%#((Podcast)Container.DataItem).Description %>'></asp:Label>

                <br /><br />

            </ItemTemplate>

       </asp:TemplateField>

     </Columns>

When I click on the Title the page refreshes and doesn't sort.  I've tried varous values in for the SortExpression with no luck.  If I take the SortExpression property out, then of course the Header 'Title' text is not a link.


C# Web Developer

When is Microsoft going to get rid of VB.NET!
dba123
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/29/2006 7:54:57 PM

0

>>>According to the sample code I provided, it should be sortDirection, not SortDirection.
C# Web Developer

When is Microsoft going to get rid of VB.NET!
dba123
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/29/2006 7:56:09 PM

0

>>>According to the sample code I provided, it should be sortDirection, not SortDirection.

Yes, I did catch that.  The original code had Capital S.


C# Web Developer

When is Microsoft going to get rid of VB.NET!
StrongTypes
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/29/2006 8:01:50 PM

0

dba123:
Yes, I did catch that.  The original code had Capital S.

Where do you see it like that?

Ryan


Ryan Olshan
Microsoft MVP, ASP.NET
Blog | Group | Website | Strong Coders Community

How to ask a question
StrongTypes
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/29/2006 8:03:41 PM

0

dba123:
I can't get it to work.  I'm not sure if I need to or what to put in the SortExpression here

You need a SortExpression. The SortExpression is the name of the column you want to sort on.

Ryan


Ryan Olshan
Microsoft MVP, ASP.NET
Blog | Group | Website | Strong Coders Community

How to ask a question
dba123
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/29/2006 8:37:05 PM

0

actually, I'm wrong, you had it correct.  I must have changed the small s to S during another error I got probably.  Sorry.
C# Web Developer

When is Microsoft going to get rid of VB.NET!
dba123
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/29/2006 8:41:18 PM

0

You' right, sorry.  You did have a small s.

 

 Yea, but when I put SortExpression='<%#((Podcast)Container.DataItem).Title %>'

Or

SortExpression=”Title”

 

It errors for  SortExpression='<%#((Podcast)Container.DataItem).Title %>':

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Databinding expressions are only supported on objects that have a DataBinding event. System.Web.UI.WebControls.TemplateField does not have a DataBinding event.

Source Error:

 

Line 30:    

Line 31:      <Columns>

Line 32:         <asp:TemplateField HeaderText="Title" SortExpression='<%#((Podcast)Container.DataItem).Title %>'>    

Line 33:             <ItemTemplate>

Line 34:                 <asp:Image ID="Image1" ImageUrl="~/images/interact/icon_podcast.gif" runat="server" />

 

On the contrary, setting it to SortExpression=”Title”, the page renders but when I click on Title in the header, the page refreshes but no sort is performed

This is why I'm so stuck and have been hitting my head for the last 2 hours!


C# Web Developer

When is Microsoft going to get rid of VB.NET!
StrongTypes
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/29/2006 9:36:00 PM

0

dba123:
On the contrary, setting it to SortExpression=”Title”, the page renders but when I click on Title in the header, the page refreshes but no sort is performed

Title is the correct SortExpression for that. What does your sorting code look like?

Ryan


Ryan Olshan
Microsoft MVP, ASP.NET
Blog | Group | Website | Strong Coders Community

How to ask a question
JEmlay
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/29/2006 11:25:12 PM

0

StrongTypes:
Since it uses a DataView for sorting, you'd have to tell it which DataTable in the DataSet to use (i..e. dataSet.Tables[0]) if your datasource is a DataSet.Ryan

That worked like a charm, thanks!

I have one more question.  Is there anyway for me to use this existing code to ONLOAD a certian colum to sort a certain way?  In other words can I manualy fire off SortDataTable?

StrongTypes
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/29/2006 11:34:16 PM

0

JEmlay:
I have one more question.  Is there anyway for me to use this existing code to ONLOAD a certian colum to sort a certain way?  In other words can I manualy fire off SortDataTable?

You could tweak the Sort property of the DataView.

Ryan


Ryan Olshan
Microsoft MVP, ASP.NET
Blog | Group | Website | Strong Coders Community

How to ask a question
dba123
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/30/2006 1:12:05 AM

0

>>>Title is the correct SortExpression for that. What does your sorting code look like?

What do you  mean, I was using your sorting code from the example.

anyway, I had to use our CodeGen classes and completely recode the Sorting method for us...


C# Web Developer

When is Microsoft going to get rid of VB.NET!
PureDevelopers
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/30/2006 5:35:26 AM

0

I am using the code below because it is the only way I have been able to get a multi select ListBox to work correctly.

Now the built in sorting doesn't work so I am looking at custom paging and sorting.

I am looking at your post and I tried pasting your code but it is not working for me.

First, the switch(sortDirection) statement is giving me an error, and I see you binding to a data table, but how does that fit in with what I am doing in my code???

Please Help!! 

 

if(IsPostBack)

{

string level = "";

foreach (ListItem selectedItem in this.lbLevel.Items)

{

// Checks if the item in the ListBox is selected or not

if (selectedItem.Selected)

{

if (level != "")

{

level = level + "," + selectedItem.Value;

}

else

{

level = selectedItem.Value;

}

}

}

string SQL =

"SELECT P.EmailFlag " +

" , P.Email " +

" , PID = P.ID " +

" , DOB = Convert(int, DATEDIFF(dd, P.DOB, GETDATE()) / 365.2425) " +

" , P.Comments " +

" , Height = CASE WHEN P.Height_Ft IS NOT NULL THEN CAST(P.Height_FT as varchar(3)) + ''' ' + CASE WHEN ISNULL(P.Height_In, 0) = 0 THEN '' ELSE CAST(P.Height_In as varchar(3)) + '''''' END ELSE '' END " +

" , LEVEL = L.[Name] " +

" , Side = S.[Name] " +

" , P.Gender " +

" , P.FirstName " +

" , P.LastName " +

" , SettingStyle = CASE WHEN Setting = 1 THEN 'Hand Setter' ELSE 'Bump Setter' END ' +

" FROM Player P " +

" INNER JOIN LEVEL L ON L.ID = P.LEVEL " +

" INNER JOIN Side S ON S.ID = P.Side " +

" WHERE P.ID <> " + Session["PID"];

if (this.txtLastName.Text.Length > 0)

{

SQL = SQL + " AND P.[LastName] LIKE '%" + this.txtLastName.Text + "%' ";

}

if (this.txtFirstName.Text.Length > 0)

{

SQL = SQL + " AND P.[FirstName] LIKE '%" + this.txtFirstName.Text + "%' ";

}

if (this.ddlGender.SelectedValue != "0")

{

SQL = SQL + " AND P.[Gender] = '" + this.ddlGender.SelectedValue + "' ";

}

if (this.ddlAgeFrom.SelectedValue != "0")

{

SQL = SQL + " AND ISNULL(Convert(int, DATEDIFF(dd, P.DOB, GETDATE()) / 365.2425), 0) >= " + this.ddlAgeFrom.SelectedValue;

}

if (this.ddlAgeTo.SelectedValue != "0")

{

SQL = SQL + " AND ISNULL(Convert(int, DATEDIFF(dd, P.DOB, GETDATE()) / 365.2425), 0) <= " + this.ddlAgeTo.SelectedValue;

}

if (level != "")

{

SQL = SQL + " AND L.[ID] IN (" + level + ") ";

}

String connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

DataSet ds = new DataSet();

SqlConnection connection = new SqlConnection(connectionString);

SqlDataAdapter adapter = new SqlDataAdapter(SQL, connection);

adapter.Fill(ds);

this.GridView1.DataSource = ds;

this.GridView1.DataBind();

adapter.Dispose();

connection.Close();

connection.Dispose();

}

aspnet_spnt
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/30/2006 5:55:25 AM

0

Rayan i have posted all the relavent code for my grid plzz have a look and i would be waiting for ur reply.

Sithlrd
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/31/2006 4:23:43 PM

0

I could care less about sorting in my case.  I just want to get paging to work. Hoping someone can aid me.

 I'm binding a Datatable to the grid (have also tried dataview and dataset). When I click a page other than the first one, the table disappears. The PageIndexChanging routine couldn't be simpler...

    protected void gvInvoices_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvInvoices.PageIndex = e.NewPageIndex;
        gvInvoices.DataBind();
    }
 Ideas?
StrongTypes
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/31/2006 6:56:08 PM

0

Sithlrd:
I could care less about sorting in my case.  I just want to get paging to work. Hoping someone can aid me.

Are you binding in pageload also? If not, do that and it should work.

Ryan

 


Ryan Olshan
Microsoft MVP, ASP.NET
Blog | Group | Website | Strong Coders Community

How to ask a question
Sithlrd
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/31/2006 7:11:53 PM

0

As is usually the case, I figured it out right after I posted. :) I added a datasource=session["Displaytable"] line in the PageIndexChanging event and all is well.

 

thanks!



 

JEmlay
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/31/2006 9:51:53 PM

0

StrongTypes:

JEmlay:
I have one more question.  Is there anyway for me to use this existing code to ONLOAD a certian colum to sort a certain way?  In other words can I manualy fire off SortDataTable?

You could tweak the Sort property of the DataView.

Ryan

Shoot, that forces me to bind the table again not the dataset.  Ah well, no biggy I guess.  Thanks again!

186 Items, 10 Pages 1 2 3 4 5 6 7 8 9 10 |< << Go >> >|


Free Download:


Web:
Sorting & Paging In GridView ? - ASP.NET Forums If you are using DataSet then this may help you. http://ryanolshan.com/articles/ c-gridview-sorting-paging-w-o-a-datasourcecontrol-datasource ...
Trying to use the FAQ " Sorting and paging in the GridView control ... http://ryanolshan.com/articles/c-gridview-sorting-paging-w-o-a-datasourcecontrol -datasource/. Regards,Vinz "Code, Beer and Music" that's my ...
[web refference]C# GridView Sorting/Paging w/o a DataSourceControl ... 2008年6月19日 ... /c-gridview-sorting-paging-woa-datasourcecontrol-datasource/C# ... on a GridView control without using a DataSourceControl DataSource ...
gridview sorting - Dot Net Search Engine swicki - powered by eurekster C# GridView Sorting/Paging w/o a DataSourceControl DataSource . ... ryanolshan. com/articles/c-gridview-sorting-paging-w-o-a-data. ... How to use sorting in GridView in ASP.Net. Add image in grid header to indicate sort direction. ...
gridview paging issue - ASP.NET Forums hi , iam using a gridview with paging ,but paging doesnot works ,it shows ... /c -gridview-sorting-paging-w-o-a-datasourcecontrol-datasource/ ...

HOW TO: Using sorting / paging on GridView w/o a DataSourceControl ... NET Forums If you are using DataSet then this may help you. http://ryanolshan. com/articles/ c-gridview-sorting-paging-w-o-a-datasourcecontrol-datasource . ...






asp.net 2.0 performance tuning considerations

insert an apostrophe into a sql string

how can i create online-exam project in asp.net using c#?

validations

creating session

error occuring like

changeing default browser .net2003

error "allowcustompaging must be true and virtualitemcount must be set for a datagrid..."

parser error message

prevent buttons from validating

whidbey: the new compilation model

what is .cms ???

sending email

what is impersonation?

unable to browse aspx pages on windows server 2003 after installing / uninstalling sp 1?

how-to: database from vwd to shared host

hide source code while deploying

blackberry and integrated windows authentication

how to convert from asp.net file to pdf file???

create a gis web application with asp.net

utilising office apps from an asp.net application

how to write event if check box get checked in datagrid

cultureinfo, currentculture, currentuiculture stuff

firefox prompt password

whidbey: accessing controls in previous page

rearrenging the auto numbers as the number of records.

execute javascript and perform postback from the same asp.net button

how to configure web service and web site for large files?

whidbey: tired with sessions? - use the new profile property to store user information

control placement

 
Search This Site:

 
  Privacy | Contact Us
All Times Are GMT