Solved

Change datasource of gridview on postback

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

732 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