Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 22nd, 2004, 12:52 PM
Registered User
 
Join Date: Jan 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, Peter!

That's exactly what I was looking for! :)
 
Old July 25th, 2007, 10:24 PM
Registered User
 
Join Date: Jul 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by planoie
 izarkhin -

I just did a test with a repeater to satisfy my own curiosity about your post.  I couldn't find a direct way to do it in the markup (which i was hoping I could) but I was able to get something to work in the code-behind.

Private Sub rptRepeater_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptRepeater.ItemDataBound
    If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
        Dim objDDL As DropDownList = CType(e.Item.FindControl("ddlList"), DropDownList)
        objDDL.SelectedIndex = objDDL.Items.IndexOf(objDDL.Items.FindByValue(e.It em.DataItem.ToString))
    End If
End Sub

e.Item.DataItem is the key.  That will give you the object of the bind, in your case it should give you the current item of the collection.  I'm making the assumption that you want to pre-select something in a dropdownlist based on the value of a property of your collection item.  My test only used an array list of integers so I could do a straight "tostring" on it without error.  You'll need to convert it to the appropriate object type before you do can access the desired property for the DDL preselect value.

Peter
------------------------------------------------------
Work smarter, not harder.
hi peter, i am having the same problem like izarkhin,and i used the above code to set the dropdown value. everything is fine, but after postback i am still getting the previous record instead of a new record.

 
Old June 19th, 2008, 03:19 PM
Registered User
 
Join Date: Jun 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi There
I have a problem who looks like this one.
I have a repeater with a dropdownlist in it. Data from repeater and dropdownlist come from different datasets.
If I display the number of records in my dropdownlist it gives me the number that I should see in the dropdownlist. But I see blank data in my dropdownlist
Here is my code
what I am missing?
Thank you

Code:
ok here is the code in the aspx.vb page

StrsqlEtab = "SELECT NO_ETAB FROM T_ETABLISSEMENT" ' WHERE No_ETAB = '" & Session("No_Etab") & "' ORDER BY NO_POSTE_B_1"

cmdEtab = New SqlCommand(StrsqlEtab, Conn)myDAEtab = New SqlDataAdapter(cmdEtab) 
Conn.Open()

myDAEtab.Fill(DsEtab)

Bud_1.DataSource = DsEtab

Bud_1.DataBind()

Bud_1.DataTextField = "NO_ETAB"

Bud_1.SelectedIndex = 1

Response.Write(Bud_1.Items.Count)  //this display the number of records that I have in my table T_ETABLISSEMENT

 

Here is the code in html

<asp:Repeater id="RepeaterAjoutPanier" runat="server">
 <ItemTemplate>
  <table align=center width=90% bgcolor="#FAFAFA"> 
   <tr>
    <td>
     <table align=center width=100% >     
      <tr class="Texte13N" bgcolor="#F5F5F5">
       <td align="center" valign="middle"><br> <b>
        <asp:DropDownList runat="server" ID="Bud_1" DataTextField="NO_ETAB" DataValueField="NO_ETAB" AutoPostBack="true" Width="10%" />-
       </td>
      </tr>

     </table> 
    </td>
   </tr>
  </table>
 </ItemTemplate>
</asp:Repeater>
 
Old June 20th, 2008, 07:03 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Don't you have to define the datatextfield before the bind?

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old June 20th, 2008, 07:11 AM
Registered User
 
Join Date: Jun 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is right.
But I still don't get any data anyway :-/

Any other idea?






Similar Threads
Thread Thread Starter Forum Replies Last Post
Object Moved to Here r_ganesh76 General .NET 2 October 14th, 2009 01:12 AM
DropDown Within Repeater ninel ASP.NET 2.0 Basics 14 May 29th, 2008 12:10 PM
Dropdown in Repeater kylemccullough ASP.NET 1.0 and 1.1 Basics 7 June 17th, 2004 01:04 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.