Wrox Programmer Forums
|
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 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 23rd, 2004, 04:54 AM
Authorized User
 
Join Date: Nov 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to koneruvijay
Default DropDownList (Very Urgent)

Hello Folks,

I am retrieve a single value from back end i mean sql server.
By using
dropdownlist1.selectedItem.value()=dtreader.getcha r(1)

which contains two values male and female

The ddl contains this code
<TR HEIGHT="30" VALIGN="Center" WIDTH="50">
<TD WIDTH="40%" ALIGN="Left">************</TD>
<TD WIDTH="40%" ALIGN="CENTER"><asp:DropDownList Width="100%" Id="DropDownListSex" MaxLength="100" CLASS="SelectBox" RUNAT="server">
<asp:ListItem Value="M">Male</asp:ListItem>
<asp:ListItem Value="F">Female</asp:ListItem>
</asp:DropDownList>
</TD>
</TR>

But i am getting this error"Specified method is not supported. "

Please reply me so soon as possible

 
Old January 23rd, 2004, 05:28 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

First of all, value is not a method but a property, so you don't need the parentheses.

Secondly, with the code you have now, you're trying to change the value of the currently selected item. I don't think that's what you want. I think you're trying to preselect the item that has the value from the DataReader, right? In that case, use the FindByValue method on the Items collection to find the right item and then set its Selected property to True.

Could you please not post "Very Urgent" messages to this list? People are here to help in their own free time. What may be important to you, may not be important to them. Stressing them up is not going to get you a quicker answer.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old January 23rd, 2004, 08:36 AM
Authorized User
 
Join Date: Nov 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to koneruvijay
Default

Imar,

I even tried that but i am getting the same error.I am trying to retrieve the value from database and based on the value i am trying to bind the text to the ddl at runtime in autopostback property.
Please tell me weather this syntax is correct or not

DropDownListSex.Items.FindByValue(selectreader.Get Char(3)).Selected=True

If it is correct i am again getting the same error Below i am sending the code in my onselectedindexchanged method PLease spare ur valuable time and give me a solutions here i am using empid with that i am trying to retrieve all the value of that id into the textbox.

Sub Emp_Select(O as Object,E as EventArgs)
Dim EmpId as Integer
EmpId=DropDownListEName.SelectedItem.Value()
If EmpId=-1 Then
Message.InnerHtml="Select Employee"
Else If(Empid<>-1) Then
Try
    StrConn.Open()
    Dim SelectCommand as SqlCommand
    SelectCommand=New SqlCommand("IN_AddEmpInfo",StrConn)
    SelectCommand.CommandType=CommandType.StoredProced ure
    SelectCommand.Parameters.Add(New SqlParameter("@AppType",SqlDbType.char,3))
    SelectCommand.Parameters("@AppType").value = "sel"
    SelectCommand.Parameters.Add(New SqlParameter("@EmpId",SqlDbType.INT))
    SelectCommand.Parameters("@EmpId").value = EmpId
    Dim SelectReader as SqlDataReader=SelectCommand.ExecuteReader()
    while selectReader.Read()
        TxtSurName.value= selectreader.getstring(0)
        TxtDOB.value = selectreader.getstring(1) TxtAge.Value=selectreader.getint32(2)
DropDownListSex.Items.FindByValue(selectreader.Get Char(3)).Selected=True
    TxtFName.Value=selectreader.GetString(4)
    TxtNationality.Value=selectreader.GetString(5)
        TxtPermanentAddress.Value=selectreader.GetString(6 )
    TxtTA.Value=selectreader.GetString(7)
    TxtPN.Value=selectreader.GetString(8)
    TxtCN.Value=selectreader.GetString(9)
    TxtCertifications.Value=selectreader.GetString(12)
    TxtPOE.Value=selectreader.GetInt32(13)
    TxtPSE.Value=selectreader.GetInt32(14)
    TxtRefName.Value=selectreader.GetString(15)
    TxtGrade.Value=selectreader.GetString(16)
    TxtPassportNo.Value=selectreader.GetString(18)
    TxtEM.Value=selectreader.GetString(19)
    TxtDOL.Value=selectreader.GetString(21)
End While
        Catch ex as exception
            response.write(ex.message)
        End Try
        End If
        StrConn.Close()
    End Sub

 
Old January 23rd, 2004, 09:06 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You have to be careful with this syntax:

DropDownListSex.Items.FindByValue(selectreader.Get Char(3)).Selected=True

The dropdownlist will most likely already have a selected item, and you can't set two items as selected if the dropdown is not multi-select (with a Male/Female selection usually wouldn't).

This code will ensure that you set ONLY the desired item as selected:

DropDownListSex.SelectedIndex = DropDownListSex.IndexOf(DropDownListSex.Items.Find ByValue(selectreader.GetChar(3))

It's a bit cumbersome but it works.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old February 2nd, 2004, 12:54 PM
Registered User
 
Join Date: Feb 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by planoie
 You have to be careful with this syntax:

DropDownListSex.Items.FindByValue(selectreader.Get Char(3)).Selected=True

The dropdownlist will most likely already have a selected item, and you can't set two items as selected if the dropdown is not multi-select (with a Male/Female selection usually wouldn't).

This code will ensure that you set ONLY the desired item as selected:

DropDownListSex.SelectedIndex = DropDownListSex.IndexOf(DropDownListSex.Items.Find ByValue(selectreader.GetChar(3))

It's a bit cumbersome but it works.

Peter
------------------------------------------------------
Work smarter, not harder.
Hi...I am trying to do what you suggested. But it seems that a DropDownList does not have the IndexOf method. Atleast, I am not able to see it!! Any ideas?

Thanks
Sj
 
Old February 2nd, 2004, 04:32 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

My bad, IndexOf is a method of the Items collection...

DropDownList.SelectedIndex = DropDownList.Items.IndexOf(DropDownList.Items.FindByValue(<value>)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dropdownlist zahyea .NET Framework 1.x 2 February 15th, 2008 10:51 AM
DropDownList jameee ASP.NET 2.0 Professional 1 October 18th, 2006 02:21 AM
dropdownlist jainnid BOOK: Beginning ASP.NET 1.0 0 December 15th, 2005 07:23 AM
dropdownlist msrnivas .NET Web Services 0 March 4th, 2004 11:01 PM





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