Board index » Web Programming » Adding a Default ListItem in a Databound Listbox in ASP.NET- Postback
|
gregsohl
|
|
gregsohl
|
Adding a Default ListItem in a Databound Listbox in ASP.NET- Postback
Web Programming236
I have read the following article www.4guysfromrolla.com/webtech/073101-1.shtml. I added the empty selection as the first option. When I click submit without choosing anything it does not return my empty string but the 2nd value in listbox. When the page reloads it selects the 2nd option by default even thou my Empty field is in the list. What do I have to do to get the empty field and databound data to act as one? - |
| David
Registered User |
Wed Dec 08 09:53:19 CST 2004
Re:Adding a Default ListItem in a Databound Listbox in ASP.NET- Postback
In your Page Load - around the BindData section - put an if/then/postback
block: if not Page.IsPostback then BindData end if David Wier MCP, MVP ASP.NET, ASPInsider aspnet101.com">aspnet101.com aspexpress.com">aspexpress.com Coming Soon - Data Management Toolkit Manage MSDE/SQL Server/MySQL/MS Access Databases from one location. augustwind.com/augustwind/dmt.aspx">augustwind.com/augustwind/dmt.aspx "Harold" <reply@togroup.com>wrote in message QuoteI have read the following article - |
| Scott
Registered User |
Wed Dec 08 10:04:53 CST 2004
Re:Adding a Default ListItem in a Databound Listbox in ASP.NET- Postback
Harold wrote:
QuoteI have read the following article dropDownList.Items[0].Selected = true; thus ensuring the first item is the selected item. -- Scott - |
| Harold
Registered User |
Wed Dec 08 14:06:13 CST 2004
Re:Adding a Default ListItem in a Databound Listbox in ASP.NET- Postback
I have the if statement and it still gives me the same results. When I
debug the code ddlcatcode.Items(0).text = "" when the page loads. When I press the search button I get ddlcatcode.Items(0).text = "13120" and I should get ddlcatcode.Items(0).text = "" because I didn't choose anything from that listbox. When the form is posted back it seems to loose the dynamic listitem I added. "David Wier" <dwier@nospamASPNet101.com>wrote in message QuoteIn your Page Load - around the BindData section - put an if/then/postback - |
| Harold
Registered User |
Wed Dec 08 14:32:36 CST 2004
Re:Adding a Default ListItem in a Databound Listbox in ASP.NET- Postback
I am now doing this and it seems to be working. Not sure if this is how it
should be done or not. If Not Page.IsPostBack Then GetData(strSQL) Else ddlCatCode.Items.Insert(0, New ListItem("", "")) End If Private Sub Page_PreRenderComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRenderComplete 'Add an empty row to catcode dropdownlist If Not Page.IsPostBack Then ddlCatCode.Items.Insert(0, New ListItem("", "")) End If End Sub "Harold" <reply@togroup.com>wrote in message QuoteI have the if statement and it still gives me the same results. When I - |
