|
-
Jul 17th, 2010, 03:21 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Gridview Paging
I have a web application which does data filtering. The return data set will be bind to Datagridview with Paging set to True.
vb Code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Using connection As New SqlConnection("Data Source=localhost\sqlexpress;Initial Catalog=26may;Integrated Security=SSPI;") Dim criteria As String = String.Empty Dim sql As String = "SELECT pk_ddlvryMasterid,pk_ddlvryno as [Dlvry No],convert(varchar,entereddate,106) as Dated" & _ ", lpono as LPO_No, Supplier FROM qDDlvryMaster" Select Case criteriaDropDownList.Text.ToUpper Case "DLVRY NO" : criteria = "PK_DDLVRYNO" Case "LPO NO" : criteria = "LPONO" Case "SUPPLIER" : criteria = "SUPPLIER" End Select Using command As New SqlCommand(sql & " where " & criteria & " LIKE @value + '%'", connection) command.Parameters.Add("@value", Data.SqlDbType.VarChar).Value = valueTextBox.Text.ToString connection.Open() Using reader As SqlDataReader = command.ExecuteReader() Dim tb As New DataTable tb.Load(reader) GridView1.DataSource = tb 'set datasource GridView1.DataBind() 'bind to gridview to view return data set End Using End Using End Using End Sub Protected Sub OnPaging(ByVal sender As Object, ByVal e As GridViewPageEventArgs) Handles GridView1.PageIndexChanging GridView1.PageIndex = e.NewPageIndex GridView1.DataBind() End Sub
The code works perfectly but every time I move to different page the gridview clear all the rows.
And also how can I make the first gridview column create link to its details page?
Last edited by jlbantang; Jul 17th, 2010 at 03:43 AM.
-
Jul 17th, 2010, 03:57 AM
#2
Fanatic Member
Re: Gridview Paging
 Originally Posted by jlbantang
The code works perfectly but every time I move to different page the gridview clear all the rows.
Code:
'do this in page load event
if not Me.IsPostBack then
'bind the gridview
end if
 Originally Posted by jlbantang
And also how can I make the first gridview column create link to its details page?
withing the <itemTemplate> take a linkbutton and then you can easily access the link button
-
Jul 17th, 2010, 04:10 AM
#3
Thread Starter
Fanatic Member
Re: Gridview Paging
hey,
I added like this:
vb Code:
If Me.IsPostBack Then Call Button1_Click(sender, e) 'call button to fillin datagrid End If
Also I added the linkbutton inside the Grid ItemTemplate but it did not do anything when the page re-run.
I want to pass the column pk_ddlvryMasterid value to the details page. Im trying to look at ASP.NET website for some tutorial similar to this regard but I cant find one. Do you any graphical/video tutorial similar to this thread?
BTW columns are not defined in gridview.
Thanks.
-
Jul 17th, 2010, 10:36 AM
#4
Frenzied Member
Re: Gridview Paging
hay,
have a look
http://msdn.microsoft.com/en-us/library/ms972948.aspx
http://www.codeproject.com/KB/webfor..._GridView.aspx
you can use the Item templates to add any thing to your GridView.
and also, your grid didn't show any thing after paging because your Grid must have its Datasource after the reload,
Code:
Protected Sub OnPaging(ByVal sender As Object, ByVal e As GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
GridView1.DataBind()
End Sub
in this code you didn't give your GridView the Datasource
You Don't Have to Rate Me.
I'm Not a Civilized Man I'm the Civilization it self
White or Black, Living or Dieing and 0 or 1 that's MY life
iam an Object in Object Oriented Life
my blog : http://refateid.blogspot.com/
twitter : @avrail
010011000111010101110110001000000100110101111001001000000101000001100011 
-
Jul 17th, 2010, 10:38 AM
#5
Frenzied Member
Re: Gridview Paging
i believe that the HOWTo will work also
You Don't Have to Rate Me.
I'm Not a Civilized Man I'm the Civilization it self
White or Black, Living or Dieing and 0 or 1 that's MY life
iam an Object in Object Oriented Life
my blog : http://refateid.blogspot.com/
twitter : @avrail
010011000111010101110110001000000100110101111001001000000101000001100011 
-
Jul 17th, 2010, 10:59 AM
#6
Fanatic Member
Re: Gridview Paging
 Originally Posted by jlbantang
hey,
vb Code:
If Me.IsPostBack Then
Call Button1_Click(sender, e) 'call button to fillin datagrid
End If
try to avoid this code;i want to tell that create a function and then call that function from where ever you want.........e.g;from the button click,page load,etc etc
-
Jul 17th, 2010, 03:35 PM
#7
Re: Gridview Paging
 Originally Posted by jlbantang
And also how can I make the first gridview column create link to its details page?
Have a look here:
http://www.asp.net/data-access/tutor...-detailview-cs
Gary
-
Jul 17th, 2010, 03:53 PM
#8
Thread Starter
Fanatic Member
Re: Gridview Paging
 Originally Posted by HowTo
try to avoid this code;i want to tell that create a function and then call that function from where ever you want.........e.g;from the button click,page load,etc etc
Can you please tell me why should I avoid the code when the function Im going to create will perform the same task.
-
Jul 17th, 2010, 03:56 PM
#9
Frenzied Member
Re: Gridview Paging
hay,
there is no harm from doing this, i believe he means you can use these lines of codes in any place you want. 
do you still have problems ??
You Don't Have to Rate Me.
I'm Not a Civilized Man I'm the Civilization it self
White or Black, Living or Dieing and 0 or 1 that's MY life
iam an Object in Object Oriented Life
my blog : http://refateid.blogspot.com/
twitter : @avrail
010011000111010101110110001000000100110101111001001000000101000001100011 
-
Jul 18th, 2010, 05:53 AM
#10
Re: Gridview Paging
What HowTo is referring to, is that you shouldn't directly call the click event of a button.
If you need to repeat the code that is executed in a button, move that code into it's own method. Then call this method from button the click event, and also in other places that you need it.
Does that make sense?
Gary
-
Jul 18th, 2010, 07:15 AM
#11
Thread Starter
Fanatic Member
Re: Gridview Paging
hey,
Yes indeed . If I am correct you just mention what he say and did not reason out the difference. I am thinking of someone answer the WHY SHOULD WE DO THAT?
-
Jul 18th, 2010, 07:47 AM
#12
Re: Gridview Paging
The reason is quite simply it is bad practice.
When you call the click event directly, you don't actually know the value of sender and e, these are normally created for you, when the click event is invoked. However, in calling it directly, you either need to create these properties, which you can't really do, or set them equal to null.
In Windows Form world, there is the PerformClick method on a button, which can be used to perform the action of clicking the button, but this does not exist in the world of ASP.Net.
Gary
-
Jul 18th, 2010, 08:34 AM
#13
Fanatic Member
Re: Gridview Paging
 Originally Posted by gep13
The reason is quite simply it is bad practice.
When you call the click event directly, you don't actually know the value of sender and e, these are normally created for you, when the click event is invoked. However, in calling it directly, you either need to create these properties, which you can't really do, or set them equal to null.
In Windows Form world, there is the PerformClick method on a button, which can be used to perform the action of clicking the button, but this does not exist in the world of ASP.Net.
Gary

thats exactly what i tried to mean but i was a bit late on this thread to explain him why should not we do that 
thanks Gary
-
Jul 18th, 2010, 08:50 AM
#14
Re: Gridview Paging
 Originally Posted by HowTo
thats exactly what i tried to mean but i was a bit late on this thread to explain him why should not we do that
thanks Gary
No probs.
-
Jul 19th, 2010, 12:01 AM
#15
Thread Starter
Fanatic Member
Re: Gridview Paging
It mean a lotta things.
thanks.
-
Jul 19th, 2010, 01:18 AM
#16
Re: [RESOLVED] Gridview Paging
Hey,
I am glad to hear that you got this sorted out.
Out of interest, what was the solution to your problem? It will help other people in the community.
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|