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 1426
nateraaaa,
Thank you very much for your time.
Now I had another problem, my code is:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string cnString = ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString;
SqlConnection cnn = new SqlConnection(cnString);
SqlCommand cmd = new SqlCommand("GetAllName", cnn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GetAllName";
cnn.Open();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "NameList");
DropDownList1.DataSource = ds;
DropDownList1.DataMember = "NameList";
DropDownList1.DataBind();
cnn.Close();
}
}
But the at Dropdown list will have "System.Data.DataRowView" instead of real data.
nateraaaa,
Thank you very much for your time.
Now I had another problem, my code is:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string cnString = ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString;
SqlConnection cnn = new SqlConnection(cnString);
SqlCommand cmd = new SqlCommand("GetAllName", cnn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GetAllName";
cnn.Open();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "NameList");
DropDownList1.DataSource = ds;
DropDownList1.DataMember = "NameList";
DropDownList1.DataBind();
cnn.Close();
}
}
But the at Dropdown list will have "System.Data.DataRowView" 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.DataSource = ds;
DropDownList1.DataValueField = "Field name for selected item value"
DropDownList1.DataTextField = "Field name for selected item Text"
DropDownList1.DataBind();
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.DataTextField ?
I had tried DropDownList1.DataTextField = "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.DataTextField = "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...
|
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...
|
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...
|
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...
| |
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...
|
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"-->...
|
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...
|
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:
-...
|
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,...
|
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,...
| |
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: 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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |