Hi All,
I am new to this field, and is using VS.2005, language is C#.
1) created a database "Test" in sql 2005, had a table "NameList", a stored proc "GetAllName "
2) created a new website, on .aspx page has a dropdown control "ddlName" Wish could have help at following:
Now I want to all the names from NameList will be populated at 'ddlName" when page loaded.
There is no problem for me to complete this task using data adapter, but I want to use stored procedure.
Thank you in advance. Your time is great appreciated.
ellen89
8 1427
nateraaaa,
Thank you very much for your time.
Now I had another problem, my code is:
protected void Page_Load(objec t sender, EventArgs e)
{
if (!IsPostBack)
{
string cnString = ConfigurationMa nager.Connectio nStrings["TestConnection String"].ConnectionStri ng;
SqlConnection cnn = new SqlConnection(c nString);
SqlCommand cmd = new SqlCommand("Get AllName", cnn);
cmd.CommandType = CommandType.Sto redProcedure;
cmd.CommandText = "GetAllName ";
cnn.Open();
SqlDataAdapter da = new SqlDataAdapter( );
da.SelectComman d = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "NameList") ;
DropDownList1.D ataSource = ds;
DropDownList1.D ataMember = "NameList";
DropDownList1.D ataBind();
cnn.Close();
}
}
But the at Dropdown list will have "System.Data.Dat aRowView" instead of real data.
nateraaaa,
Thank you very much for your time.
Now I had another problem, my code is:
protected void Page_Load(objec t sender, EventArgs e)
{
if (!IsPostBack)
{
string cnString = ConfigurationMa nager.Connectio nStrings["TestConnection String"].ConnectionStri ng;
SqlConnection cnn = new SqlConnection(c nString);
SqlCommand cmd = new SqlCommand("Get AllName", cnn);
cmd.CommandType = CommandType.Sto redProcedure;
cmd.CommandText = "GetAllName ";
cnn.Open();
SqlDataAdapter da = new SqlDataAdapter( );
da.SelectComman d = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "NameList") ;
DropDownList1.D ataSource = ds;
DropDownList1.D ataMember = "NameList";
DropDownList1.D ataBind();
cnn.Close();
}
}
But the at Dropdown list will have "System.Data.Dat aRowView" instead of real data.
Hi, The problem is in this line, - DropDownList1.DataSource = ds;
ur binding a dataset to a dropdownlist, a dataset may contain more than one table also, so there comes the problem, even if u hv used Datamember,the table name to which the "NameList" column belongs is not specified,So u hv to do this, - DropDownList1.DataSource = ds.Tables[0]
The '[0]' denotes the index of the datatable in the dataset.
Im sure this works...
Thanks
Saran
Sarah,
Thank you very much. I had tried, unfortunately, I have no lucky.
I am not sure the .DataMember property, NameList is my table name, with 2 columns (firstName, lastName).
Gusee I should not have the column name in my code because I am using stored procedure to get the result. This stored procedure is very simple and tested in sql server 2005.
Thanks again,
ellen89
Hi, ur code correct but to display text in drop down control u have to set column name, same for value
DropDownList1.D ataSource = ds;
DropDownList1.D ataValueField = "Field name for selected item value"
DropDownList1.D ataTextField = "Field name for selected item Text"
DropDownList1.D ataBind();
Thank you!
Now the problem is I want to show the full name on the dropdown list, but the Name is stored in databas as FirstName & LastName (2 columns).
What should I put for DropDownList1.D ataTextField ?
I had tried DropDownList1.D ataTextField = "FirstName+ ' '+LastName", it gave run time error.
ellen89
I had solved this problem by using a VIEW table at SQL server to have FirstName and LastName at same column.
Thank you for all help.
ellen89
You not need to create view for this single reason, just add column in ur sql query
as FirstName + ' '+LastName as Name.
and
DropDownList1.D ataTextField = "Name"
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Dannyboyo |
last post by:
I have what I hope is a simple request. I can't really code in javascript, but I am pretty good at cusomizing it with
slight modifications. I code in ASP and HTML.
I am trying to capture customer input of product names to put on custom labels we make. Some of the labels will have our
product names on them, but the customer can add other...
|
by: Mark Goldin |
last post by:
How can I populate a dropdownlist with data from a database using
Microsoft.ApplicationBlocks.Data ?
Thanks
|
by: Yul |
last post by:
Hi,
We are in the process of designing an ASP.NET app, where a user will
enter some 'Customer ID' to be queried in the database. If the ID is
valid, several stored procedures will be called to populate multiple
webpages containing customer information. There isn't a one-to-one
correlation between the stored procedure and a webpage. In other...
|
by: JIM.H. |
last post by:
Hello,
I have two Tables: Table1: GroupID1, GroupName1 and Table2:GroupID2,
GroupName2.
I have only one dropdown list (DropDownList1) in my application and through
a stored procedure I want to populate my DropDownList1 from GroupName1 and
GroupName2. How should I write my query?
Thanks,
Jim.
|
by: Chris Kettenbach |
last post by:
Hello all,
Quick question. I have a listbox that is populated by items from a database.
When the user select something from the list, I want to populate another
listbox based on the selection in the first.
Example lstCompany contains a list of company names with the primary key
field hidden. After user selects a company, I want to pass that...
| |
by: blouie |
last post by:
Is there a way that a bound ddl control can:
1. display the bound data, even if it does not match a selection in
the DDL?
2. allow the user to enter something other than the look up values?
I have a bound dropdown list that retrieves it's selections from a
look-up table. The DDL is bound to a database table and unless the
value in the...
|
by: Mike P |
last post by:
I am trying to populate a dropdown from a stored procedure, but I am
getting the error 'Object doesn't support this property or method:
'Next' :
<!--#include file="include_connection.asp"-->
<!--#include file="adovbs.inc"-->
<%
set objConn = server.createobject("adodb.connection")
|
by: Javilen |
last post by:
Hello,
Maybe one of you can offer a possible solution to the problem I have below.
The request to me is to build a dynamically populating dropdown list from a text box.(something similar to Google Suggest.)
The idea is that the client wants to come in and search for something but may only know part of the name. So they type it in.
Eg....
|
by: TonFrere |
last post by:
Hello,
I'm building a windows form application in Visual C# using VS 2005. On my form I need to populate a combobox with Invoices# linked to the current reccord's Order# value. This means that:
- The combobox should repopulate if the user changes the value of Order#.
- The combobox should repopulate if the user moves through records (using the...
|
by: ellen89 |
last post by:
Hi All,
I am new to this field, and is using VS.2005, language is C#.
1) created a database "Test" in sql 2005, had a table "NameList", a stored proc "GetAllName"
2) created a new website, on .aspx page has a dropdown control "ddlName"
Wish could have help at following:
Now I want to all the names from NameList will be populated at...
|
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...
| |
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...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |