Home > Ask the Microsoft .Net Development Experts > Visual Basic .NET Questions & Answers > Datagrid issue: 'onselection' is not populating
Ask The Win Development Expert: Questions & Answers
EMAIL THIS

Datagrid issue: 'onselection' is not populating

Daniel Cazzulino EXPERT RESPONSE FROM: Daniel Cazzulino

Pose a Question
Other Win Development Categories
Meet all Win Development Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 13 July 2005

I need to show a Dropdownlist in page load, and based on my selection from Dropdownlist I need to populate a Datagrid , the Dropdownlist is independent of the datagrid . Is it possible to do that.

Please note that the Dropdownlist is independent and not part of the grid .

Based on the selection from the list the grid will be populated.

if(!page.Ispostback)
{
SqlConnection myConnection = new SqlConnection("server=MANSV107;database=EPPRD;uid=kpi_user; pwd=kpi_user"); myConnection.Open(); SqlDataAdapter myCommand = new SqlDataAdapter("select name from Plants where p_id not in(5)",myConnection); //SqlDataAdapter myCommand = new SqlDataAdapter("select * from kpi_conscomp_v where plant like 'Manchester%'and year='2004'", myConnection); DataSet ds =new DataSet(); myCommand.Fill(ds,"kpi");

DropDownList1.DataSource=ds;
DropDownList1.DataTextField="name";
DropDownList1.DataBind();
/********************************/
// form = (HtmlForm) this.FindControl("Form1"); // form.Controls.Add( dropdownlist1 ); // DropDownList1.Style["POSITION"] = "absolute"; DropDownList1.Style["TOP"] = "120"; }

It is working fine but onselection from the List the Datagrid is not populating.

The code is private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e) { SqlConnection myConnection = new SqlConnection("server=MANSV107;database=EPPRD;uid=kpi_user; pwd=kpi_user"); myConnection.Open();

SqlDataAdapter da=new SqlDataAdapter("select * from kpi_conscomp_v where plant like'" + DropDownList1.SelectedValue +"'",myConnection); DataSet ds=new DataSet(); da.Fill(ds,"KPI"); MyDataGrid.DataSource=ds.Tables["KPI"].DefaultView;
MyDataGrid.DataBind();
}


>

Daniel Cazzulino responds:

There are a couple things to keep in mind.

First, if you dropped the dropdownlist on the design surface, you don't need to call form.Controls.Add. If you haven't, and you're creating the control programmatically, you just need to do this: Controls.Add (it will call the Page.Controls.Add).

Secondly, DropDownList does not postback by default when a selection is made. If you want that to happen, just set the AutoPostBack property to 'true,' and the SelectedIndexChanged event will be fired right away when the user changes the selection on the client side.


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Visual Basic .NET
Access VB .NET Windows control on client side
Drop down list server control creates error message
Converting floating values to byte form
Read data from parallel port
What is the use of these constructors?
Give me an ODBC connect, with SQL authentication
Converting EXE-files to VB components
Generating classes like we did in VB6
Manipulating text through VB.NET
Converting Windows applications to VB .NET

ASP.NET development best practices
Introduction to ASP.NET's Model View Controller (MVC) Design Pattern
Silverlight, Ajax components require different approach to UI
LINQ Learning Guide: LINQ and Web applications
VB code download home page
VB code: File manipulation downloads
Localization practices for .NET 2.0: It's still about the architecture
Creating custom ASP.NET 2.0 profile providers
.NET development in the trenches
Microsoft developers balancing age-old issues, barrage of new technology
SearchVB.com's Podcast Page

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
136 browser colors with names  (SearchWinDevelopment.com)
ASP.NET  (SearchWinDevelopment.com)
browser  (SearchWinDevelopment.com)
Document Object Model  (SearchWinDevelopment.com)
domain name  (SearchWinDevelopment.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



Windows Development - White Papers, News and Expert Advice
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts