Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Gridview how to autopostback?

Status
Not open for further replies.

flynbye

Programmer
Nov 16, 2001
68
0
0
US
Good Morning All :)

Well the problem that I'm having is that I've built a gridview of available employee information with the data coming from a stored SQL procedure linked to a submit button which retrieves the records I require. All of this works fine but I'd like to implement paging on the gridview and now I'm having issues with the autopostback. When the next page is selected the gridview disappears, but if I click on the submit button (which triggers an autopostback) then the gridview comes back displaying the correct page view.

Any suggestions on how I can generate an autopostback for this control? I'd thought of simply calling the submit button so that it triggers an autopostback but the submit requires a sender and event value I'm not sure how to return.

Thanks for any help!
Chris

I always makes things much harder than they should be... that way later I can slap myself in the forhead after spending hours and hours on two lines of code and say to myself "DUH!"
 
It sounds as though you aren't rebinding the data again in the PageIndexChanging event. Can you post an example of your code for this function?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim ConnectionString As String
ConnectionString = System.Configuration.ConfigurationManager.AppSettings("appConnectionString")
Dim cnnSql As New SqlConnection(ConnectionString)
Dim cmdSQL As New SqlCommand("[getAvailEmpByDept]", cnnSql)
Dim adpTest As SqlDataAdapter = New SqlDataAdapter

Dim Br As Integer
Dim BrStr As String
Dim DeptAG As String
Dim DeptOFFICE As String
Dim DeptPEST As String
Dim DeptWDO As String

Br = Me.DropDownList1.Text
BrStr = Br.ToString("00")
If Me.chkAG.Checked = True Then DeptAG = "3" Else DeptAG = "0"
If Me.chkOFFICE.Checked = True Then DeptOFFICE = "4" Else DeptOFFICE = "0"
If Me.chkPEST.Checked = True Then DeptPEST = "5" Else DeptPEST = "0"
If Me.chkWDO.Checked = True Then DeptWDO = "2" Else DeptWDO = "0"

cmdSQL.CommandType = CommandType.StoredProcedure

With cmdSQL.Parameters
.Add(New SqlParameter("@Br", BrStr))
.Add(New SqlParameter("@DeptAG", DeptAG))
.Add(New SqlParameter("@DeptOFFICE", DeptOFFICE))
.Add(New SqlParameter("@DeptPEST", DeptPEST))
.Add(New SqlParameter("@DeptWDO", DeptWDO))
End With

adpTest.SelectCommand = cmdSQL

cnnSql.Open()
Dim ds As New DataSet
adpTest.Fill(ds)

If ds.Tables.Count > 0 Then
GridView1.DataSource = ds
GridView1.DataBind()
End If
End Sub


I always makes things much harder than they should be... that way later I can slap myself in the forhead after spending hours and hours on two lines of code and say to myself "DUH!"
 
What I've posted is the submit button code... and I am not doing anything on the pageindexchanging event... sooo... hrm not sure how I would go about rebinding but will play with that for a moment whilst you digest the above :)

Thanks!
Chris

I always makes things much harder than they should be... that way later I can slap myself in the forhead after spending hours and hours on two lines of code and say to myself "DUH!"
 
ca8msm said:
It sounds as though you aren't rebinding the data again in the PageIndexChanging event. Can you post an example of your code for this function?
That's just the code for a submit button. What do you have in the above function?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Nothing going on in the rebind...

Chris

I always makes things much harder than they should be... that way later I can slap myself in the forhead after spending hours and hours on two lines of code and say to myself "DUH!"
 
As ca8msm has said, you need to grab the data, set the page index of the grid, and rebind the grid in the SelectedPageIndex event.

Jim
 
Sorry been AFK... this is a Gridview(2.0)



I always makes things much harder than they should be... that way later I can slap myself in the forhead after spending hours and hours on two lines of code and say to myself "DUH!"
 
Nothing going on in the rebind...
Well that's why it isn't doing anything then. You can't expect it to know what to do unless you write the relevant code. I'd suggest reading up on the PageIndexChanging event.



____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
As an example, check out my post in thread855-1182415


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top