Solved

Drop Down within Repeater - How to get value from dbase

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Javascript in a user control not working 17 65
ASP.NET Web API or ASP.NET Core MVC? 3 51
Interview questions for support of a legacy ASP.NET site 4 37
Split in Javascript 5 30
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

919 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

19 Experts available now in Live!

Get 1:1 Help Now