473,386 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

populate data in datagrid depend on dropdown selection

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

Feb 17 '06 #1
3 1621
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=mySQLServe r;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();

"riyaz" wrote:
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

Feb 17 '06 #2
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
Feb 17 '06 #3
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
Feb 17 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nithin | last post by:
My code as an txt attachment. I have 2 drop down list boxes that on selection populate text boxes from my database table. I am able to display the correct values in these text boxes. I have 2...
2
by: Wysiwyg | last post by:
I was hoping to get some opinions on the efficiency of various methods of reusing the same dropdown list data. Here is the situation: Multiple panels on maintenance pages with TAB menus across...
1
by: Vijay Kerji | last post by:
Hi, I have a datagrid with dropdown list and Remove hyperlink in it as columns. When I remove a row from the datagrid, Dropdown list selection is retaining its previous value. i.e, removed...
14
by: Barney | last post by:
How can I populate a textbox from a dataview? I have a dataset i'm filtering on and i want to populate several textboxes based on that filter. How can i get that to work? I've tried: ...
1
by: Mike P | last post by:
Is it possible when populating a datagrid to populate a dropdownlist column based upon the value populated to another row in the datagrid? (i.e. I have a drop down which I want to populate...
1
by: priyanka.freakout | last post by:
Hi All, In my form I have created a dropdown box which is populated with data from a database on page load and i have also created a dropdwon box and what i intend on doing is displaying data...
3
by: rn5a | last post by:
A SqlDataReader is populated with the records from a SQL Server 2005 DB table. The records retrieved depends upon 2 conditions (the conditions depend on what a user selects in an ASPX page). If...
0
by: anjupt | last post by:
Hi, Will i able populate data into a listbox on dropdown selection. I have a dropdown with classnames and sections and on the selction of this dropdown i want list of students with respect to...
5
by: =?Utf-8?B?SnVsaWEgQg==?= | last post by:
Hi, I wonder if anyone can help? I've got a web form (intranet), .net version 1.1. I've got a sub that populates a datatable in a dataset, dependent on a dropdown field selection. This works...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.