Solved

Drop Down within Repeater - How to get value from dbase

Posted on 2008-09-29
5
249 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 125 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

685 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