Solved

Change datasource of gridview on postback

Posted on 2009-06-30
5
581 Views
Last Modified: 2013-11-27
How do I change the gridview datasource in an if statement

this is as far as i've got.

  Protected Sub ddlCountry_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlCountry.SelectedIndexChanged
        If ddlCountry.Text = "All" Then
            GridView1.DataSourceID = dsCategoryAll
        End If

    End Sub

0
Comment
Question by:edjones1
  • 2
5 Comments
 
LVL 18

Accepted Solution

by:
David Robitaille earned 500 total points
ID: 24747683
add "GridView1.DataBind"

If ddlCountry.Text = "All" Then
            GridView1.DataSourceID = dsCategoryAll
            GridView1.DataBind
       End If

0
 
LVL 7

Expert Comment

by:meispisces
ID: 24747762
To bind a gridview you need to have 2 things

(A) Datasource : the one which holds records, could be dataset, dropdownlist, arrays etc. Assigned to controls (e.g. Grid view) like Gridview1.Datasource= your datasource
(B) DataBind : Binding database to controls which is Gridview1.DataBind

Now you wish to change the datasource on postback. So if that changes on first time page load you would get your (old) datasource and after then page loads you would get your (new) datasource. Is that what you wished? If no, then please explain or post your code or any link which justified your example. I'm asking such long questions, as this is quite rare of changing datasource and that too on postbacks

thanks
0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 25259400
commment id: 24747683 should solve the problem.

no new form the asker.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question