RSS Forums RSS
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 7162 | Replies: 12
Reply
Join Date: Mar 2006
Location: Egypt,Cairo
Posts: 36
Reputation: web developer is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
web developer's Avatar
web developer web developer is offline Offline
Light Poster

Help Paging in dataGrid

  #1  
Mar 16th, 2006
Hi all
I have a problem in paging datagrid ..
I have a datagrid and i have template columns in it - is that affect on paging ? , so why paging doesn't work .
i tried the following code after allowing paging to datagrid:

private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
DataGrid1.DataBind();

}

does that should code work ?
or could any one give me a successeded code please .
Thanx..
Life Is A Big Code
Rushdy Ibrahim
Egypt
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2006
Posts: 4
Reputation: raghunath.kunta is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
raghunath.kunta raghunath.kunta is offline Offline
Newbie Poster

Re: Paging in dataGrid

  #2  
Mar 17th, 2006
Can you please tell us what is exactly happening when you run this code.
Reply With Quote  
Join Date: Mar 2006
Posts: 84
Reputation: web_developer is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
web_developer web_developer is offline Offline
Junior Poster in Training

Re: Paging in dataGrid

  #3  
Mar 19th, 2006
hey man
if u put a template in the datagrid, that doesn't affect. for the paging to work well u should write the source below.
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e) Handles DataGrid1.PageIndexChanged {
DataGrid1.CurrentPageIndex = e.NewPageIndex;
<!-- here u should open connection
execute the query
close the connection
then data binding -->
DataGrid1.DataBind();
Reply With Quote  
Join Date: Mar 2006
Location: Egypt,Cairo
Posts: 36
Reputation: web developer is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
web developer's Avatar
web developer web developer is offline Offline
Light Poster

Re: Paging in dataGrid

  #4  
Mar 19th, 2006
Thank you very much ,
But i did that before ,
The problem is i am using template columns , and change the properties of the controls(in the template columns) by a for loop which change all controls according to the index of the loop. but the compiler fires error when the index exceeds the page size

for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{

DataGridItem dgi = DataGrid1.Items[i]; // this is the error
LinkButton c_lb=(LinkButton)dgi.FindControl("Client_LB");
c_lb.Text=ds.Tables[0].Rows[i][0].ToString();
}

Exception
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Life Is A Big Code
Rushdy Ibrahim
Egypt
Reply With Quote  
Join Date: Mar 2006
Posts: 4
Reputation: raghunath.kunta is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
raghunath.kunta raghunath.kunta is offline Offline
Newbie Poster

Re: Paging in dataGrid

  #5  
Mar 20th, 2006
You definitely get this error as the data shown in grid is only 10 records(depending on the count you mentioned) but you are looping through the all the records in dataset.

Originally Posted by web developer
Thank you very much ,
But i did that before ,
The problem is i am using template columns , and change the properties of the controls(in the template columns) by a for loop which change all controls according to the index of the loop. but the compiler fires error when the index exceeds the page size

for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{

DataGridItem dgi = DataGrid1.Items[i]; // this is the error
LinkButton c_lb=(LinkButton)dgi.FindControl("Client_LB");
c_lb.Text=ds.Tables[0].Rows[i][0].ToString();
}

Exception
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Reply With Quote  
Join Date: Mar 2006
Posts: 84
Reputation: web_developer is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
web_developer web_developer is offline Offline
Junior Poster in Training

Re: Paging in dataGrid

  #6  
Mar 19th, 2006
i dont know man
i didnt face this problem
i used as i told u and didnt face this problem
sorry
Reply With Quote  
Join Date: Mar 2006
Location: Egypt,Cairo
Posts: 36
Reputation: web developer is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
web developer's Avatar
web developer web developer is offline Offline
Light Poster

Help Re: Paging in dataGrid

  #7  
Mar 20th, 2006
Thanx very much
I know that this is the problem
and how can i change all the controls data without a loop throw all rows
i ask you , if u have another solution plz .
i have 3 days trying it ,i spent more and more time.
Thanx again
waitting any response.
bye
Life Is A Big Code
Rushdy Ibrahim
Egypt
Reply With Quote  
Join Date: Mar 2006
Posts: 4
Reputation: raghunath.kunta is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
raghunath.kunta raghunath.kunta is offline Offline
Newbie Poster

Re: Paging in dataGrid

  #8  
Mar 21st, 2006
There are some grid events like ItemBound where you can set controls values. If you can tell me when exactly(On which event) and which record you want to display in controls it will be great.
Reply With Quote  
Join Date: Mar 2006
Location: Egypt,Cairo
Posts: 36
Reputation: web developer is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
web developer's Avatar
web developer web developer is offline Offline
Light Poster

Help Re: Paging in dataGrid

  #9  
Mar 21st, 2006
Thank you very much
i have just tried the ItemDataBound event which set values to items in the bound time , it is really great ..
but also i have a problem in that event that how can i get a text from a cell from the e handler ?
i tried the following code in that event

DataGridItem dgi=e.Item;
SqlDataAdapter ad = new SqlDataAdapter("select Client_Name,Proj_Name,Task_Name,Task_Progress,Task_EndDate,Proj_Color,Task.Task_Id from Task,Client,Project where Task_Owner='"+Session["Uname"].ToString()+"' and Task.Task_Proj_Id=Project.Proj_Id and Project.Proj_Client_Id =Client.Client_Id and Task.Task_Id="+dgi.Cells[0].Text,con);
DataSet ds1= new DataSet();
LinkButton c_lb=(LinkButton)dgi.FindControl("Client_LB");
c_lb.Text=ds1.Tables[0].Rows[0][0].ToString();


but aslo the problem of paging is still exist ..
and i put in the 1st column the field of the task_id in databinding of the datagrid (as a Bound column) where can get the rest of columns data by quering by it .. although it returns an empty value at the first and the last rows of items

if you have a nice code to handle this event , i will be very pleased
Thank you very much
Life Is A Big Code
Rushdy Ibrahim
Egypt
Reply With Quote  
Join Date: Mar 2006
Location: Egypt,Cairo
Posts: 36
Reputation: web developer is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
web developer's Avatar
web developer web developer is offline Offline
Light Poster

News Re: Paging in dataGrid

  #10  
Mar 21st, 2006
Ok
Thanx very much
the event just worked and the problem is solved ..
i used try and catch to handle the exception .. and all is right now .
Thanx very much
and Thanx for all who help me
Bye

:p :p :p :p
Life Is A Big Code
Rushdy Ibrahim
Egypt
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:42 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC