Solved

Drop Down within Repeater - How to get value from dbase

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now