Solved

Change datasource of gridview on postback

Posted on 2009-06-30
5
574 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now