473,670 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1630
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.Co nnectionString = "Persist Security Info=False;Inte grated
Security=SSPI;d atabase=northwi nd;server=mySQL Server;Connect Timeout=30";
myConnection.Op en();

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

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

myAdapter.Fill( myDataSet, "table1");
DataGrid1.DataS ource = myDataSet;
DataGrid1.DataB ind();

myConnection.Cl ose();

"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.Argument NullException: 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.DataS ource = myDataSet
Line 224: DataGrid1.DataB ind()

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
2427
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 questions: 1) I would like the user update these text fields that get populated with data from the database. For some reason I get the error when I change the textbox value.
2
1889
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 the top showing different panels. A DropDownList with a 50+ value/text entries exists on more than one panel but only one will be displayed at a time. Examples might be US states, countries, category codes, etc.
1
1962
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 Dropdown item selection is applied to the next dropdown list. Is there any way to fix this problem?
14
3652
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: dsDetails = GetCars() dvDetails = New DataView With dvDetails
1
2115
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 differently for each row with user names based upon a UserRegionID which is also a column in the row). Since you don't actually know the value of the UserRegionID until the data is already bound to the datagrid, how do you do this?
1
1619
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 re;ated to dropdown selection into a data grid. I have attached part of the code. Can someone please help me out on this cos i am really finding it
3
4358
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 condition1 is true, then the SqlDataReader will be populated with the records existing in table1 & will return 0 to the calling function but if condition2 is true, then the SqlDataReader will be populated with the records from another table named...
0
1284
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 class and section to be populated in the listbox ThankYou
5
3745
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 great, but if the user selects another item from the dropdown field and the sub runs again, the original data is overwritten. How do I store the original data and add the new datarow without overwriting the original? Here's my code: Protected...
0
8471
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8386
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8592
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7421
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6216
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5686
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4213
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4393
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2802
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.