Wrox Programmer Forums
|
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 September 18th, 2006, 01:52 PM
Friend of Wrox
 
Join Date: May 2005
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default dropdownlist in datagrid update

hi,
I have a datagrid.in this datagrid I have a dropdownlist
like below:
the value exists in the database.
how should I get the value from db and set it to the selected value of dropdown and then update it?
 <asp:dropDownList runat="server" id="Flevel" >
            <asp:Listitem value="1">Friend</asp:Listitem>
            <asp:Listitem value="2">Good Friend</asp:Listitem>
            <asp:Listitem value="3">Best Friend</asp:Listitem>
            <asp:Listitem value="4">Acquainted</asp:Listitem>
            <asp:Listitem value="5">Haven't Met</asp:Listitem>
            </asp:dropDownList>



 
Old September 18th, 2006, 02:18 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

you need to do something like this:

<asp:dropdownlist runat=server id="something" SelectedIndex="<%#intIndex%>" />

where intIndex is declared as public and set on the backend. (You must use selectedIndex as selectedValue isn't accessible through the tag like this)

--Stole this from a moderator

I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
 
Old September 18th, 2006, 02:48 PM
Friend of Wrox
 
Join Date: May 2005
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

so you say I should write code and then set the intIndex
but can you give example
here is my code
Sub Display_Friends()

Dim strSQL as string
strSQL = "SELECT * from users"
Dim objConnection as New SQLConnection(strConnection)
Dim DataSet As DataSet = New DataSet()
    Dim Cmd as New SQLCommand(strSql,objConnection)


Dim Adapter As SqlDataAdapter = New SqlDataAdapter(Cmd)
Adapter.Fill(DataSet,"friends")
Session("DataView") = dataset.Tables("friends").DefaultView()

    displayFriends.DataSource = Session("DataView")

    if dataset.tables("friends").rows.count >0 then
    displayFriends.DataBind()
    displayFriends.visible="true"

    strCount=dataset.tables("friends").rows.count
    else
    displayFriends.visible="false"
    msgStatus.visible="true"
    msgStatus.text=NoMsg
    end if

End Sub

 
Old September 18th, 2006, 03:05 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Since you are statically adding the ListItems it is a tad harder to get the correct index; I almost always use a stored procedure to populate Dropdown values.

Anyway.

What I would do is dynamically create you dropdown lists which will then give you the ability to loop through the result set and set the appropriate index; as it stands right now you have to set up a case statement:

switch([database value])
{
   case "Friend":
       intIndex = 0;
       break;
   case "Good Friend":
       intIndex = 1;
       break;
...etc
}

--Stole this from a moderator

I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
 
Old September 18th, 2006, 03:20 PM
Friend of Wrox
 
Join Date: May 2005
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot






Similar Threads
Thread Thread Starter Forum Replies Last Post
Add a Dropdownlist to update fields on a page cesemj ASP.NET 2.0 Basics 1 October 4th, 2007 11:24 AM
Sql Update Stament via DropDownlist in GridView DarkForce ASP.NET 2.0 Basics 7 August 8th, 2007 09:08 AM
dropdownlist in datagrid ansowmya ASP.NET 1.0 and 1.1 Basics 1 June 14th, 2006 02:49 PM
update state thru dropdownlist debjanib ASP.NET 1.0 and 1.1 Professional 0 May 17th, 2006 02:56 PM
Datagrid update, dropdownlist database insertion herman ASP.NET 1.0 and 1.1 Professional 2 October 11th, 2003 01:31 AM





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