So this applies in every case with dropdownlists?
Whether you're filling out a form or populating a form
with information from a database?
Why do I keep seeing this format then
myDDL.SelectedItem.Text ?
Also I'm not populating the DDL from a database. I'm
simply using the ITEM property.
Thanks,
Anna
--- Peter Brunone <[EMAIL PROTECTED]> wrote:
> > And I've always used
> > myDDL.SelectedItem.Text
>
> ���If your intent was to select the correct item,
> then you've always been wrong :)� This code will
> alter the content of the currently selected item
> rather than selecting the correct item.� See below
> for the proper way to select a new item.
> ���If, on the other hand, you really do want to
> change the text of the selected item, then ignore
> this message and carry on.
>
> Cheers,
>
> Peter
>
> From: Anna Leon [EMAIL PROTECTED]
>
> Yes what you said below is true.
>
> This is what I'm using:
>
> where MR is always the first item in the collection.
>
> And I've always used
> myDDL.SelectedItem.Text
>
> Thanks,
> Anna
>
> --- Peter Brunone wrote:
>
> >
> > Actually, from the explanation below, it looks
> > like her code is simply changing the value/text of
> > the first item in the DDL (instead of changing the
> > selected item).
> >
> > Anna, what code are you using to select the
> > correct item in your list? I would guess that
> > you're doing something like this:
> >
> > myDDL.SelectedItem.Value = "MS"
> > myDDL.SelectedItem.Text = "MS"
> >
> > when you should be doing something like this:
> >
> > myDDL.SelectedValue = "MS" ' ASP.NET 1.1
> > or
> > myDDL.SelectedIndex =
> > myDDL.Items.IndexOf(myDDL.Items.FindByValue("MS"))
> >
> >
> >
> > From: Mark E [EMAIL PROTECTED]
> >
> > Anna,
> >
> > It looks as tho your code that populates the DDL's
> > is returning the value plus all 4 prefix
> selections.
> > That would explain why the item is always first
> but
> > there is a duplicate within the DDL.
> >
> > I recall dealing with this previously and I had my
> > stored procedure use a union. I first grabbed the
> > prefix for the customer, then used a union to
> return
> > all *other* prefixes that did not match the one
> for
> > this customer. Like this:
> >
> > -- get the prefix for this customer
> > select Prefix
> > from tblPrefix, tblCustomer
> > where tblCustomer.Prefix = tblPrefix.Prefix
> >
> > union
> >
> > -- get all other prefixes
> > select Prefix
> > from tblPrefix, tblCustomer
> > where tblCustomer.Prefix <> tblPrefix.Prefix
> >
> > If you can't get it, post your SQL that retrieves
> > your prefixes so that we can see it.
> >
> > Mark
> >
> > Anna Leon wrote:
> > Everything looks okay I believe.
> >
> > Here's what I have noticed:
> >
> > - The FIRST item in the dropdownlist gets changed
> > (repeated twice) if you select something other
> than
> > the first item.
> >
> > e.g. On the form, if you select:
> >
> > "MS." then on the edit page, the dropdownlist is
> > displayed with the following: MS/MRS/MISS/MS
> >
> > "MRS." then on the edit page, the dropdownlist is
> > displayed with the following: MRS/MRS/MISS/MS
> >
> > "MR." then on the edit page, the dropdownlist is
> > displayed with the following: MR/MRS/MISS/MS
> > (* THIS IS THE ONLY ONE THAT HAS NO PROBLEMS)
> >
> > "MISS." then on the edit page, the dropdownlist is
> > displayed with the following: MISS/MRS/MISS/MS
> >
> > Why is that? What am I doing wrong?
> >
> > Thanks,
> > Anna
> >
> > --- Mark E wrote:
> >
> > > Anna,
> > >
> > > I would start with the data on page 2. Check all
> > > the values before they go to the database. If
> that
> > > seems OK, check your stored procedure
> > "PutCustomer".
> > > Run it manually to ensure that the correct
> record
> > > (and only this record) is getting updated.
> > >
> > > Mark
> > >
> > > Anna Leon wrote:
> > > I am actually following this article:
> > >
> > >
> >
>
http://www.aspnetpro.com/NewsletterArticle/2003/02/asp200302fw_l/asp200302fw_l.asp
> > >
> > > And the only exception is that with mines, some
> > > fields
> > > are null thus the textboxes for editing would
> not
> > > get
> > > populated with anything. Although, it's been
> said
> > > that
> > > there are spaces in there instead.
> > >
> > > Yoru're saying Trim() plus .ToString() should
> > solve
> > > the problem, which it does.
> > >
> > > The query to update the record is on the above
> > page.
> > >
> > > Thanks,
> > > Anna
> > >
> > > --- Mark E wrote:
> > >
> > > > I doubt the Trim function had anything to do
> > with
> > > > it. Maybe the query that updated the record?
> We
> > > > would have to see the code to tell what caused
> > it.
> > > >
> > > > Mark
> > > >
> > > > Anna Leon wrote:
> > > > Something else happened...
> > > >
> > > > I applied Trim() to all the textboxes. When I
> > edit
> > > a
> > > > record on the second page (on a form w/
> > textboxes
> > > > and
> > > > dropdownlists), I changed the title from Mr.
> to
> > > Mrs.
> > > > as a test, after I saved, I noticed the
> > > dropdownlist
> > > > items changed. Mr is no longer a choice and I
> > have
> > > > Mrs. twice. What happened there? This also
> > > affected
> > > > several other records (and I didn't even touch
> > > > them).
> > > >
> > > > Thanks,
> > > > Anna
> > > >
> > > > --- Mark E wrote:
> > > >
> > > > > Anna,
> > > > >
> > > > > The Trim() function trims (or removes) all
> > > leading
> > > > > and trailing spaces from a string. In your
> > > case,
> > > > > that's all you had so it removed everything.
> I
> > > > > would recommend using on all your textboxes
> > > there
> > > > > the user input is an open text field.
> > > > >
> > > > > Mark
> > > > >
> > > > > Anna Leon wrote:
> > > > > This seems to work. What exactly does Trim()
> > do?
> > > > > Will
> > > > > it affect the other textboxes (where they
> are
> > > > > populated since their fields aren't null)?
> It
> > > > > doesn't
> > > > > look like it.
> > > > >
> > > > > Is this a permanent solution? And is it the
> > best
> > > > > one?
> > > > >
> > > > > Thanks,
> > > > > Anna
> > > > >
> > > > >
> > > > > --- Mark E wrote:
> > > > >
> > > > > > If you have 200+ spaces, that may be
> taking
> > up
> > > > the
> > > > > > value of the control.
> > > > > >
> > > > > > Try triming your values when you set them
> to
> > > the
> > > > > > control and see if it helps:
> > > > > >
> > > > > > lname.Text =
> Trim(dr("LastName").ToString())
> > > > > >
> > > > > > If it's empty space, the Trim() function
> > will
> > > > > remove
> > > > > > it.
> > > > > >
> > > > > > Mark
> > > > > >
> > > > > > Anna Leon wrote:
> > > > > > Mark,
> > > > > >
> > > > > > The textboxes are limited to maxlength of
> > 200.
> > >
> > > > > >
> > > > > > When I tried Peter's method:
> > > > > > > > a View Source on your page to see
> what's
> > > > > getting
> > > > > > > put
> > > > > > > > into the value
> > > > > > > > attribute of the textboxes. You can
> even
> > > > copy
> > > > > > the
> > > > > > > > output and paste it
> > > > > > > > into the form at
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
http://aspalliance.com/peterbrunone/analyzethis/analyzethis.asp
> > > > > > > > to see
> > > > > > > > if there are any funny characters in
> > > there.
> > > > > >
> > > > > > The textboxes that aren't populated with
> > > > anything
> > > > > > (meaning the fields are null in the
> > database),
> > > > the
> > > > > I
> > > > > > see only spaces (probably like 200) are
> > > getting
> > > > > put
> > > > > > into the value atrribute.
> > > > > >
> > > > > > Thanks,
> > > > > > Anna
> > > > > >
> > > > > >
> > > > > > --- Mark E wrote:
> > > > > >
> > > > > > > Anna,
> > > > > > >
> > > > > > > Are your textboxes disabled or limited
> in
> > > > > someway?
> > > > > > >
> > > > > > > Mark
> > > > > > >
> > > > > > > Anna Leon wrote:
> > > > > > > Hi,
> > > > > > >
> > > > > > > Thanks for the function, but it's not
> > > working
> > > > > > > either.
> > > > > > > =/
> > > > > > >
> > > > > > > -Anna
> > > > > > >
> > > > > > >
> > > > > > > --- David Renz
> > > > wrote:
> > > > > > >
> > > > > > > > anna,
> > > > > > > >
> > > > > > > >
> > > > > > > > if it is the null values ... i have a
> > > simple
> > > > > > > > function that deals with
> > > > > > > > null values.
> > > > > > > >
> > > > > > > > Public Function
> > EnsureStringDefault(ByVal
> > > > > > sValue)
> > > > > > > As
> > > > > > > > String
> > > > > > > > If sValue Is DBNull.Value Then
> > > > > > > > Return ""
> > > > > > > > Else
> > > > > > > > Return sValue
> > > > > > > > End If
> > > > > > > > End Function
> > > > > > > >
> > > > > > > > use it like so:
> > > > > > > > lname.Text =
> > > > > EnsureStringDefault(dr("LastName"))
> > > > > > > >
> > > > > > > > same for numbers
> > > > > > > >
> > > > > > > > Public Function
> > EnsureNumericDefault(ByVal
> > > > > > iValue)
> > > > > > > > As Integer
> > > > > > > > If iValue Is DBNull.Value Then
> > > > > > > > Return 0
> > > > > > > > Else
> > > > > > > > Return iValue
> > > > > > > > End If
> > > > > > > > End Function
> > > > > > > >
> > > > > > > > they work for me on several sites,
> > though
> > > i
> > > > am
> > > > > > not
> > > > > > > > facing the same
> > > > > > > > problem you explained.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > >>> [EMAIL PROTECTED] 05/13/2005
> > > > 8:22:46
> > > > > AM
> > > > > > > >>>
> > > > > > > >
> > > > > > > > I would suggest
> > > > > > > >
> > > > > > > > lname.Text = dr("LastName").ToString()
> > > > > > > > fname.Text =
> dr("FirstName").ToString()
> > > > > > > >
> > > > > > > > and so on. If you still have problems,
> > > post
> > > > a
> > > > > > > link
> > > > > > > > (if you can) or do
> > > > > > > > a View Source on your page to see
> what's
> > > > > getting
> > > > > > > put
> > > > > > > > into the value
> > > > > > > > attribute of the textboxes. You can
> even
> > > > copy
> > > > > > the
> > > > > > > > output and paste it
> > > > > > > > into the form at
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
http://aspalliance.com/peterbrunone/analyzethis/analyzethis.asp
> > > > > > > > to see
> > > > > > > > if there are any funny characters in
> > > there.
> > > > > > > >
> > > > > > > > Cheers,
> > > > > > > >
> > > > > > > > Peter
> > > > > > > >
> > > > > > > > From: Anna Leon [EMAIL PROTECTED]
> > > > > > > >
> > > > > > > > Private Sub Page_Load(ByVal sender As
> > > > > > > System.Object,
> > > > > > > > ByVal e As System.EventArgs)
> > > > > > > >
> > > > > > > > Dim ds As DataSet
> > > > > > > > Dim dr As DataRow
> > > > > > > > Dim ConnectionStr As String =
> > > > > > > >
> > > > >
> > ConfigurationSettings.AppSettings("ConnString")
> > > > > > > > Dim adpt As SqlDataAdapter
> > > > > > > > Dim conn As SqlConnection
> > > > > > > > Dim cmd As SqlCommand
> > > > > > > > Dim Id As Integer
> > > > > > > >
> > > > > > > > If Not IsPostBack Then
> > > > > > > > If
> > > > Request.QuerySTring("CardVerificationUID")
> > > > > Is
> > > > > > > > Nothing Then
> > > > > > > > Status.Text = "New record"
> > > > > > > > uid.Text = "New"
> > > > > > > >
> > > > > > > > ElseIf
> > > > > > Request.QueryString("CardVerificationUID")
> > > > > > > =
> > > > > > > > "New" Then
> > > > > > > > Status.TExt = "New record"
> > > > > > > > uid.Text = "New"
> > > > > > > >
> > > > > > > > Else
> > > > > > > > Try
> > > > > > > > Status.Text = "Record retrieved"
> > > > > > > > Id =
> > > > > > > >
> > > > >
> > CInt(Request.QueryString("CardVerificationUID"))
> > > > > > > > ds = New DataSet()
> > > > > > > > conn = New
> SqlConnection(ConnectionStr)
> > > > > > > > cmd = New
> > > SqlCommand("GetCardVerification",
> > > > > > > > conn)
> > > > > > > > cmd.CommandType =
> > > > CommandType.StoredProcedure
> > > > > > > >
> > cmd.Parameters.Add("@CardVerificationUID",
> > > > > > > > SqlDbType.Int).Value = Id
> > > > > > > > adpt = New SqlDataAdapter(cmd)
> > > > > > > > adpt.Fill(ds, "CardVerification")
> > > > > > > > if
> > > ds.Tables("CardVerification").Rows.Count
> > > > =
> > > > > > > > 0 Then
> > > > > > > > Status.Text = "Record not found."
> > > > > > > >
> > > > > > > > Else
> > > > > > > > dr =
> > > > > > > > ds.Tables("CardVerification").Rows(0)
> > > > > > > > uid.Text = dr("UID")
> > > > > > > > title.SelectedItem.Text = dr("Title")
> > > > > > > > lname.Text = dr("LastName")
> > > > > > > > fname.Text = dr("FirstName")
> > > > > > > > middleinitial.Text =
> > > > > > > > dr("MiddleInitial")
> > > > > > > > email.Text = dr("Email")
> > > > > > > > phone.Text = dr("Phone")
> > > > > > > > phoneext.Text = dr("PhoneExt")
> > > > > > > > .
> > > > > > > > .
> > > > > > > > .
> > > > > > > >
> > > > > > > > Thanks,
> > > > > > > > Anna
> > > > > > > >
> > > > > > > > --- Peter Brunone wrote:
> > > > > > > > > Hi Anna,
> > > > > > > > >
> > > > > > > > > If you can show me the code you're
> > using
> > > > to
> > > > > > pull
> > > > > > > > > the data, I can show you where it
> > goes.
> > > > > > Usually
> > > > > > > I
> > > > > > > > > just do it to the field when it
> comes
> > > out
> > > > of
> > > > > > the
> > > > > > > > > data structure (the first time you
> > > assign
> > > > it
> > > > > > > > > somewhere).
> > > > > > > > >
> > > > > > > > > Cheers,
> > > > > > > > >
> > > > > > > > > Peter
> > > > > > > > >
> > > > > > > > > From: Anna Leon [EMAIL PROTECTED]
> > > > > > > > >
> > > > > > > > > Hi Peter,
> > > > > > > > >
> > > > > > > > > Can you provide an example? Where
> > would
> > > I
> > > > > set
> > > > > > > the
> > > > > > > > > value to the field.ToString()
> because
> > in
> > > > the
> > > > > > > code,
> > > > > > > > > there's 2 sections where one
> retrieves
> > > the
> > > > > > > record
> > > > > > > > > and
> > > > > > > > > populating the data into the
> > textboxes,
> > > > and
> > > > > > > > second,
> > > > > > > > > updating the record in the database
> > with
> > > > > > > whatever
> > > > > > > > > changes made in the textboxes
> (except
> > > the
> > > > > > empty
> > > > > > > > ones
> > > > > > > > > don't do anything).
> > > > > > > > >
> > > > > > > > > Thanks,
> > > > > > > > > Anna
> > > > > > > > >
> > > > > > > > > --- Peter Brunone wrote:
> > > > > > > > > > Hi Anna,
> > > > > > > > > >
> > > > > > > > > > If you are populating these
> > textboxes,
> > > > try
> > > > > > > > setting
> > > > > > > > > > the value
> > > > > > > > > > equal to the field.ToString()
> > instead
> > > of
> > > > > > just
> > > > > > > > the
> > > > > > > > > > field.
> > > > > > > > > >
> > > > > > > > > > Cheers,
> > > > > > > > > >
> > > > > > > > > > Peter
> > > > > > > > > >
> > > > > > > > > > -----Original Message-----
> > > > > > > > > > From:
> > > > > [email protected]
> > > > > > On
> > > > > > > > > > Behalf Of sas0riza
> > > > > > > > > >
> > > > > > > > > > Hello,
> > > > > > > > > >
> > > > > > > > > > I have 2 asp.net pages where the
> > first
> > > > has
> > > > > a
> > > > > > > > > > datagrid and the second
> > > > > > > > > > page allows you edit the record
> > > > depending
> > > > > > > which
> > > > > > > > > one
> > > > > > > > > > you clicked from
> > > > > > > > > > the datagrid.
> > > > > > > > > >
> > > > > > > > > > Not all records have all fields
> > filled
> > > > in.
> > > > > > The
> > > > > > > > > > record is retrieved
> > > > > > > > > > and the data is populated into a
> > form
> > > > > > > > (textboxes)
> > > > > > > > > > for editing on the
> > > > > > > > > > second page. Some textboxes come
> > back
> > > > > empty
> > > > > > > > since
> > > > > > > > > > it's NULL, which
> > > > > > > > > > is okay.
> > > > > > > > > >
> > > > > > > > > > BUT, when I try to type (edit
> mode)
> > > > > > something
> > > > > > > > into
> > > > > > > > > > the empty
> > > > > > > > > > textbox, nothing shows up no
> matter
> > > what
> > > > I
> > > > > > > type.
> > > > > > > > > >
> > > > > > > > > > I think the null value is the
> cause.
> > > > > > > > > >
> > > > > > > > > > So, how do I fix this?
> > > > > > > > > >
> > > > > > > > > > Someone told me that I should make
> > > sure
> > > > > that
> > > > > > I
> > > > > > > > > don't
> > > > > > > > > > return a null
> > > > > > > > > > value from the database.
> > > > > > > > > >
> > > > > > > > > > Any help is greatly appreciated.
> > > > > > > > > >
> > > > > > > > > > Thanks,
> > > > > > > > > > Anna
> >
> >
> > [Non-text portions of this message have been
> > removed]
> >
> >
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Small Business - Try our new Resources site
> http://smallbusiness.yahoo.com/resources/
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
> [Non-text portions of this message have been
> removed]
>
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/