Solved

Change datasource of gridview on postback

Posted on 2009-06-30
5
584 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:Ed
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

691 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