Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Drop Down within Repeater - How to get value from dbase

Posted on 2008-09-29
5
Medium Priority
?
255 Views
Last Modified: 2012-05-05
Hi

I have a drop down with a repeater control and want to populate it from a value in the database.

I have set the datasource of the repeater and the drop down value is within this datasource

I am using the "Item Created" of the repeater to populate the drop down with values but I don't know how to get it to select a the value from the database. E.g. like

ddlCurrency.Items.FindByText(Utility.BlankIfNull(objReader("firm_funds_managed_currency"))).Selected = True

Any help and code ;) would be great

0
Comment
Question by:patelajk
  • 2
  • 2
5 Comments
 
LVL 20

Accepted Solution

by:
informaniac earned 500 total points
ID: 22594960
Try placing this in the ItemDataBound event of the repeater

ddlCurrency.Items.FindByText(Utility.BlankIfNull(objReader("firm_funds_managed_currency"))).Selected = True
0
 

Author Comment

by:patelajk
ID: 22594990
I got a" Invalid attempt to read when no data is present"
when i put code below:



Protected Sub parentRepeater_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles parentRepeater.ItemDataBound
		Dim objReader As SqlDataReader = DataAccess.ReaderFromSP("EXEC sp_g_GP_Profile " & Request.QueryString("FirmID"))
		Dim ddlBoard As DropDownList = CType(e.Item.FindControl("ddlBoard"), DropDownList)
		ddlBoard.Items.FindByText(Utility.BlankIfNull(objReader("Board_Rep"))).Selected = True
 
	End Sub
 
	Private Sub Repeater()
'populate repeater and call from Page_load
		Dim objReader As SqlDataReader = DataAccess.ReaderFromSP("EXEC sp_g_GP_Profile " & Request.QueryString("FirmID"))
	
		parentRepeater.DataSource = objReader
		parentRepeater.DataBind()
		objReader.Close()
		
	End Sub

Open in new window

0
 

Author Comment

by:patelajk
ID: 22595008
its ok i been sill forgor to add a while loop
0
 
LVL 20

Expert Comment

by:informaniac
ID: 22595022
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then

//........... Write code here

End If
0
 
LVL 21

Expert Comment

by:naspinski
ID: 22595474
Is it always the same data?  If that is the case, just use a LInqDataSource or SqlDataSource and set the DDL DataSourceID... no code needed.
<asp:Repeater ... >
  <ItemTemplate>
    <asp:DropDownList DataSourceID="lds" ... />
  </ItemTemplate>
</asp:Repeater>
 
<asp:LinqDataSource id="lds" ... />

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question