Solved

Drop Down within Repeater - How to get value from dbase

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 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