populate data in datagrid depend on dropdown selection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

dear mvps

i am a beginner for asp.net
,i want to produce the data in the datagrid based upon the selection from
the dropdown list.

plz give me some code for me to develop this

regards
niyaz
 
Hey,

Try out this sample code.. This code assumes the data in dropdownlist list
all the departments of a company, and by selecting one it list all employees
for that department..

code on page load event:
Dim myConnection As New SqlConnection();
Dim mySql as String;
myConnection.ConnectionString = "Persist Security Info=False;Integrated
Security=SSPI;database=northwind;server=mySQLServer;Connect Timeout=30";
myConnection.Open();

if (IsPostBack)
mySQL = "SELECT * FROM employee where departmentname = '" +
dropdownlist1.selectedvalue + "'";
else
mySQL = "SELECT * FROM employee";

Dim myAdapter As New SqlDataAdapter(mySQL,myConnection);
Dim myDataSet as DataSet;

myAdapter.Fill(myDataSet, "table1");
DataGrid1.DataSource = myDataSet;
DataGrid1.DataBind();

myConnection.Close();
 
dear mvp

i am getting this error, whether we have to write databind() for
dropdownlist ?



Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: dataSet

Source Error:


Line 220: Dim myDataSet As DataSet
Line 221:
Line 222: myAdapter.Fill(myDataSet, "table1") <---
Line 223: DataGrid1.DataSource = myDataSet
Line 224: DataGrid1.DataBind()

regards
Niyaz
 
Riyaz,

Try what happens is you change it to

dim MyDataset as New Dataset

Please don't start your questions with "dear MVP's" there are lucky enough a
lot of other people who wants and are able to help. You limit your own
answers with doing that.

I hope this helps,

Cor
 
Back
Top