Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: A simple way to fill a select drop down from an SQL database conn- ection


Message #1 by "McCloy, Russell" <Russell.McCloy@B...> on Fri, 7 Dec 2001 09:22:13 +1100
What are you using to retrieve your data?  DataSet, DataReader?

Here's a simple example of populating a selectbox:

//on the ASPX page:
<asp:DropDownList id="myDDL" runat="server"></asp:DropDownList>

//on the codebehind (or server script), using C#:

private void Page_Load(object sender, EventArgs e)
{
	SqlConnection cn = new SqlConnection("myconnectionstring");
	cn.Open()
	SqlCommand cmd = new SqlCommand("select * from authors");
	SqlDataReader rdr 
cmd.ExecuteReader(CommandBehavior.CloseConnection);

	myDDL.DataValueField = "au_id";	//would make the author id the value
attribute
	myDDL.DataTextField = "au_lname";	//would make the author last
name the display value
	myDDL.DataSource = rdr;
	myDDL.DataBind();
	rdr.Close()
}

-----Original Message-----
From: McCloy, Russell [mailto:Russell.McCloy@B...] 
Sent: Thursday, December 06, 2001 3:22 PM
To: ASPX_Professional
Subject: [aspx_professional] A simple way to fill a select drop down from an
SQL database conn ection


Hi all,

I know this is a lame question. 
I have just started with ASP.NET and have built a few web pages that access
a database. The one thing I cant find is simply how to populate a HTMLSelect
control. I have a list of numbers in a table in the database and want these
to show in the HTMLSelect 
when the page_load runs.

Can someone please give me a quick solution or point me to a help site
somewhere??

thanks

RuSs

-----Original Message-----
From: ASPX_Professional digest [mailto:aspx_professional@p...]
Sent: Thursday, 29 November 2001 11:00 AM
To: aspx_professional digest recipients
Subject: aspx_professional digest: November 28, 2001


-----------------------------------------------
When replying to the digest, please quote only
relevant material, and edit the subject line to
reflect the message you are replying to.
-----------------------------------------------

The URL for this list is:
http://p2p.wrox.com/list.asp?list=aspx_professional

ASPX_PROFESSIONAL Digest for Wednesday, November 28, 2001.

1. Re: CC Validation
2. Overriding the default currancy format
3. passing null values to an sqlCommand

----------------------------------------------------------------------

Subject: Re: CC Validation
From: "Brandon Levitt" <levittbr@m...>
Date: Wed, 28 Nov 2001 15:04:57
X-Message-Number: 1

Check out the quickstart...

http://www.gotdotnet.com/quickstart/aspplus/doc/webvalidation.aspx

This doesn't have exactly what you need, but I think it would get you 
started on your own custom validator or regex validator.

> I need to code up the Luhn Mod 10 system or something similar to do
> credit card number validation before it is sent off to the server.  I 
> have some code but it is coded for VB and I need it to work with C# any 
> information and/or help woudl be greatly appreciated..
> 
> Morgan


----------------------------------------------------------------------

Subject: Overriding the default currancy format
From: "Brandon Levitt" <levittbr@m...>
Date: Wed, 28 Nov 2001 15:11:03
X-Message-Number: 2

With the following line of code...

System.Globalization.NumberFormatInfo.CurrentInfo.CurrencyDecimalDigits = 0

...I can override the number of digits following the decimal point on a 
per page basis where ever the "{c}" formatting string is used.

I would like to do this for the whole application.  What are my options?

TIA

----------------------------------------------------------------------

Subject: passing null values to an sqlCommand
From: "Brandon Levitt" <levittbr@m...>
Date: Wed, 28 Nov 2001 17:50:40
X-Message-Number: 3

I have a VB.Net method that creates a sqlCommand object and the parameters 
associated with a stored proc.  I want to send null as one of the 
parameter values.  However, when I set the parameter.value property = 
System.DBNull, sql profiler shows that the sql 'default' keyword is used 
instead.  So, how do I send my stored proc the value null?


---

END OF DIGEST

---
VBug Winter Conference 2001 

Make no mistake - there's a great learning curve 
for developers moving from COM to .NET.  So why 
would you want to be a pioneer and cross the bridges 
first?  Attend the .NET Developer's Conference 
(28th to 30th November 2001) In London and realise 
the benefits of adopting the technology early.  By 
attending you'll understand the key challenges and 
be left with a thorough understanding of the major 
.NET fundamentals.   If you're already working 
with .NET this is a must-attend event.  

http://www.vbug.co.uk/redirect.asp?url=39&id=17

---
You are currently subscribed to 
aspx_professional as: russell.mccloy@b...
$subst('Email.Unsub')

$subst('Email.Unsub').

  Return to Index