Displaying Selected Value in Dropdown list

Last post 07-11-2008 3:14 AM by Qin Dian Tang - MSFT. 11 replies.

Sort Posts:

  • Displaying Selected Value in Dropdown list

    07-08-2008, 3:26 PM
    • Member
      34 point Member
    • schauhan13
    • Member since 07-08-2008, 7:15 PM
    • Posts 158

    Hi I m new to asp.net

    i have 3 dropdowlists naming country ,state,city.

    My problem is when i go to update.aspx page

    i want to show selected values in dropdownlist. Please help me its urgent.

    For eg,

    in database for certain user value for city is Chicago, i want when i go to update.aspx.

    The selected dity is highlited.

    Thanx in advance 

  • Re: Displaying Selected Value in Dropdown list

    07-08-2008, 4:13 PM
    • Contributor
      4,017 point Contributor
    • gbogea
    • Member since 04-14-2008, 11:17 PM
    • Brazil
    • Posts 575

    You have to programatically set the selected value on each ddl. Something like this:

    ddlCountry.SelectedValue = "US";

    ddlState.SelectedValue = "IL";

    ddlCity.SelectedValue = "Chicago" ;

    Is this what you needed?

    Gabriel Bogéa (http://www.gbogea.com)
    -----------------
    Please 'Mark as Answer' the post(s) that helped you
  • Re: Displaying Selected Value in Dropdown list

    07-08-2008, 4:35 PM
    • Member
      34 point Member
    • schauhan13
    • Member since 07-08-2008, 7:15 PM
    • Posts 158

    My scenario is that i have data in gridview and when i click on select linkbutton it shows corresponding values in textboex and dropdownlists. What i want is the selected city in gridview like Chicago for a particular row must be highlites value in the corresponding dropdownlist. but i dont know how to do dat. Below is the code,

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged

    Txtempid.Text = GridView1.SelectedRow.Cells(0).Text

    Txtlname.Text = GridView1.SelectedRow.Cells(1).Text

    Txtfname.Text = GridView1.SelectedRow.Cells(2).Text

    ' Dddate.SelectedValue = GridView1.SelectedRow.Cells(3).Text

    Txtadd.Text = GridView1.SelectedRow.Cells(4).Text

    ddcnt.SelectedIndex = ddcnt.Items.IndexOf(ddcnt.Items.FindByValue(
    "GridView1.SelectedRow.Cells(7).Text")) !!!!!!!!!! Here is the problem if i give chicago here it will highlight dat but how to do it wid grid

    Txtzipcod.Text = GridView1.SelectedRow.Cells(8).Text

    Dddept.SelectedIndex = Dddept.Items.IndexOf(Dddept.Items.FindByValue(
    "GridView1.SelectedRow.Cells(9).Text"))

    TxtJobTit.Text = GridView1.SelectedRow.Cells(10).Text

    TxtJobDesc.Text = GridView1.SelectedRow.Cells(11).Text

    Txtwphn.Text = GridView1.SelectedRow.Cells(12).Text

    Txtcphn.Text = GridView1.SelectedRow.Cells(13).Text

    Txtemail.Text = GridView1.SelectedRow.Cells(14).Text

    Txtfax.Text = GridView1.SelectedRow.Cells(15).Text

    End Sub

     

    Thanx in advance

  • Re: Displaying Selected Value in Dropdown list

    07-08-2008, 5:28 PM
    • Contributor
      4,017 point Contributor
    • gbogea
    • Member since 04-14-2008, 11:17 PM
    • Brazil
    • Posts 575

    schauhan13:

    ddcnt.SelectedIndex = ddcnt.Items.IndexOf(ddcnt.Items.FindByValue("GridView1.SelectedRow.Cells(7).Text")) !!!!!!!!!! Here is the problem if i give chicago here it will highlight dat but how to do it wid grid

     

    I didn't understand. This is working, right? I have tested here and it works fine:

    DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(GridView1.SelectedRow.Cells[1].Text));

    What is your error? What do you mean by: "but how to do it wid grid"?

    Gabriel Bogéa (http://www.gbogea.com)
    -----------------
    Please 'Mark as Answer' the post(s) that helped you
  • Re: Displaying Selected Value in Dropdown list

    07-08-2008, 9:48 PM
    • Member
      34 point Member
    • schauhan13
    • Member since 07-08-2008, 7:15 PM
    • Posts 158

    Well thanks but the problem is i run this code and i do not get any error but my grid is not populating the dropdownlist. its still blank!!!!

  • Re: Displaying Selected Value in Dropdown list

    07-08-2008, 10:13 PM
    • All-Star
      91,768 point All-Star
    • vinz
    • Member since 10-05-2007, 3:47 PM
    • Cebu, Philippines
    • Posts 13,769
    • TrustedFriends-MVPs

    schauhan13 :

    but my grid is not populating the dropdownlist. its still blank!!!!

    How do you bind your DDL? can you post your codes here.. 

    "Code,Beer and Music ~ my way of being a programmer"

  • Re: Displaying Selected Value in Dropdown list

    07-09-2008, 8:16 AM
    • Member
      34 point Member
    • schauhan13
    • Member since 07-08-2008, 7:15 PM
    • Posts 158

    I am binding ddcnt(ddl for country) using SQLDataSource2 .And ddl for state on selected indexed changed for country and ddl for city on selected indexed changed for state. My problem is that when i select row from gridview then the selected values in gridview are highlighted in DDL's but i am not able to do this. So plz help.Sure here is the code:-

    update.aspx.vb

    Imports System.Data

    Imports System.Data.SqlClient

    Imports System.IO

    Partial Class Administrator_EmpUpd

    Inherits System.Web.UI.Page

    Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("cn").ConnectionString)

    Dim cmd As New SqlCommand

    Protected Sub Btnupd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btnupd.Click

    cmd.CommandText = "updemp"

    cmd.CommandType = CommandType.StoredProcedure

    cmd.Connection = con

    con.Open()

    cmd.Parameters.Add(
    "@eid", SqlDbType.Int).Value = Txtempid.Text

    cmd.Parameters.Add("@ln", SqlDbType.VarChar).Value = Txtlname.Text

    cmd.Parameters.Add("@fn", SqlDbType.VarChar).Value = Txtfname.Text

    cmd.Parameters.Add("@dob", SqlDbType.NVarChar).Value = Convert.ToString(Dddate.SelectedItem) & "/" & Convert.ToString(Ddmonth.SelectedItem) & "/" & Convert.ToString(Ddyear.SelectedItem)

    cmd.Parameters.Add("@ad", SqlDbType.VarChar).Value = Txtadd.Text

    cmd.Parameters.Add("@cid", SqlDbType.Int).Value = Ddcity.SelectedValue

    cmd.Parameters.Add("@zp", SqlDbType.Int).Value = Txtzipcod.Text

    cmd.Parameters.Add("@ph", SqlDbType.VarChar).Value = "~/images/" & FileUpload1.FileName

    cmd.Parameters.Add("@did", SqlDbType.Int).Value = Convert.ToString(Dddept.SelectedValue)

    cmd.Parameters.Add("@jt", SqlDbType.VarChar).Value = TxtJobTit.Text

    cmd.Parameters.Add("@jd", SqlDbType.VarChar).Value = TxtJobDesc.Text

    cmd.Parameters.Add("@sl", SqlDbType.VarChar).Value = Ddsal.SelectedValue

    cmd.Parameters.Add("@st", SqlDbType.VarChar).Value = Ddshift.SelectedValue

    cmd.Parameters.Add("@wf", SqlDbType.NVarChar).Value = Txtwphn.Text

    cmd.Parameters.Add("@cf", SqlDbType.NVarChar).Value = Txtcphn.Text

    cmd.Parameters.Add("@em", SqlDbType.NVarChar).Value = Txtemail.Text

    cmd.Parameters.Add("@fx", SqlDbType.NVarChar).Value = Txtfax.Text

    cmd.ExecuteNonQuery()

    Txtempid.Text = ""

    Txtlname.Text = ""

    Txtfname.Text = ""

    Txtadd.Text = ""

    Txtzipcod.Text = ""

    TxtJobTit.Text = ""

    TxtJobDesc.Text = ""

    Txtwphn.Text = ""

    Txtcphn.Text = ""

    Txtemail.Text = ""

    Txtfax.Text = ""

    gridbind()

    End Sub

    Private Sub gridbind()

    Dim adp As New SqlDataAdapter("select empid,lname,fname,dob,addr,city,statename,cntname,zipcode,photo,dept,job_tit,job_desc,w_phone,c_phone,email,fax from tbemp,tbcity,tbstate,tbcnt,tbdept where tbemp.cityid=tbcity.cityid and tbcity.stateid=tbstate.stateid and tbstate.cntid = tbcnt.cntid and tbemp.deptid=tbdept.deptid", con)

    Dim ds As New DataSet

    adp.Fill(ds)

    GridView1.DataSource = ds

    GridView1.DataBind()

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Page.IsPostBack = False Then

    con.Open()

    filldata()

    Txtempid.Focus()

    gridbind()

    End If

    End Sub

    Protected Sub ddcnt_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddcnt.SelectedIndexChanged

    Dim adp As New SqlDataAdapter("select * from tbstate where cntid='" & ddcnt.SelectedValue & "'", con)

    Dim ds As New DataSet

    adp.Fill(ds)

    Ddstate.DataSource = ds

    Ddstate.DataTextField = "statename"

    Ddstate.DataValueField = "stateid"

    Ddstate.DataBind()

    End Sub

    Protected Sub Ddstate_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Ddstate.SelectedIndexChanged

    Dim adp As New SqlDataAdapter("select * from tbcity where stateid='" & Ddstate.SelectedValue & "'", con)

    Dim ds As New DataSet

    adp.Fill(ds)

    Ddcity.DataSource = ds

    Ddcity.DataTextField = "city"

    Ddcity.DataValueField = "cityid"

    Ddcity.DataBind()

    End Sub

    Private Sub filldata()

    With Ddmonth.Items

    .Add("Jan")

    .Add("Feb")

    .Add("March")

    .Add("April")

    .Add("May")

    .Add("June")

    .Add("July")

    .Add("Aug")

    .Add("Sept")

    .Add("Oct")

    .Add("Nov")

    .Add("Dec")

    End With

    Dim i As Integer = 1935

    Dim n As Integer = 2009

    While i < n

    Ddyear.Items.Add(i)

    i = i + 1

    End While

    Dim j As Integer = 1

    Dim m As Integer = 31

    While j <= m

    Dddate.Items.Add(j)

    j = j + 1

    End While

    End Sub

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged

    Txtempid.Text = GridView1.SelectedRow.Cells(0).Text

    Txtlname.Text = GridView1.SelectedRow.Cells(1).Text

    Txtfname.Text = GridView1.SelectedRow.Cells(2).Text

    ' Dddate.SelectedValue = GridView1.SelectedRow.Cells(3).Text

    Txtadd.Text = GridView1.SelectedRow.Cells(4).Text

    ddcnt.SelectedIndex = ddcnt.Items.IndexOf(ddcnt.Items.FindByValue(
    "GridView1.SelectedRow.Cells(7).Text")) !!!! Here is the problem the selected value does not get highlighted.

    Txtzipcod.Text = GridView1.SelectedRow.Cells(8).Text

    Dddept.SelectedIndex = Dddept.Items.IndexOf(Dddept.Items.FindByValue(
    "GridView1.SelectedRow.Cells(9).Text"))

    TxtJobTit.Text = GridView1.SelectedRow.Cells(10).Text

    TxtJobDesc.Text = GridView1.SelectedRow.Cells(11).Text

    Txtwphn.Text = GridView1.SelectedRow.Cells(12).Text

    Txtcphn.Text = GridView1.SelectedRow.Cells(13).Text

    Txtemail.Text = GridView1.SelectedRow.Cells(14).Text

    Txtfax.Text = GridView1.SelectedRow.Cells(15).Text

    End Sub

    End Class

     

     

     

     

     

    update.aspx

    <%@ Page Language="VB" MasterPageFile="~/MasterSub.master" AutoEventWireup="false" CodeFile="EmpUpd.aspx.vb" Inherits="Administrator_EmpUpd" title="Untitled Page" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <asp:Label ID="Lblempid" runat="server" Height="19px" Style="z-index: 100; left: 320px;

    position: absolute; top: 160px" Text="Employee ID" Width="128px"></asp:Label>

    <asp:Label ID="Lblwphn" runat="server" Height="19px" Style="z-index: 101; left: 320px;

    position: absolute; top: 840px" Text="Work Phone" Width="128px"></asp:Label>

    <asp:Label ID="Lblzipcode" runat="server" Height="19px" Style="z-index: 102; left: 720px;

    position: absolute; top: 304px" Text="Zip Code" Width="128px"></asp:Label>

    <asp:DropDownList ID="Ddcity" runat="server" Style="z-index: 103; left: 1080px;

    position: absolute; top: 400px" Width="112px" AutoPostBack="True" TabIndex="10">

    </asp:DropDownList>

    <asp:Label ID="Lblcity" runat="server" Style="z-index: 104; left: 992px; position: absolute;

    top: 400px" Text="City" Width="56px"></asp:Label>

    <asp:Label ID="Lblstate" runat="server" Height="19px" Style="z-index: 105; left: 720px;

    position: absolute; top: 400px" Text="State" Width="80px"></asp:Label>

    <asp:Label ID="LblCnt" runat="server" Height="19px" Style="z-index: 106; left: 320px;

    position: absolute; top: 400px" Text="Country" Width="128px"></asp:Label>

    <asp:Label ID="Lbladdr" runat="server" Height="19px" Style="z-index: 107; left: 320px;

    position: absolute; top: 304px" Text="Address" Width="128px"></asp:Label>

    <asp:Label ID="Lblfname" runat="server" Height="19px" Style="z-index: 108; left: 720px;

    position: absolute; top: 208px" Text="First Name" Width="128px"></asp:Label>

    <asp:Label ID="Lbllname" runat="server" Height="19px" Style="z-index: 109; left: 320px;

    position: absolute; top: 208px" Text="Last Name" Width="128px"></asp:Label>

    <asp:Label ID="Lblcphn" runat="server" Height="19px" Style="z-index: 110; left: 720px;

    position: absolute; top: 840px" Text="Cell Phone" Width="128px"></asp:Label>

    <asp:Label ID="Lblemail" runat="server" Style="z-index: 111; left: 720px; position: absolute;

    top: 896px" Text="Email ID " Width="128px"></asp:Label>

    <asp:Label ID="Lblfax" runat="server" Height="19px" Style="z-index: 112; left: 320px;

    position: absolute; top: 896px" Text="Fax" Width="128px"></asp:Label>

    <asp:Label ID="Lblphoto" runat="server" Style="z-index: 113; left: 320px; position: absolute;

    top: 960px" Text="Photo" Width="128px"></asp:Label>

    <asp:TextBox ID="Txtfax" runat="server" Style="z-index: 114; left: 496px; position: absolute;

    top: 896px" TabIndex="18"></asp:TextBox>

    <asp:TextBox ID="Txtcphn" runat="server" Style="z-index: 115; left: 912px; position: absolute;

    top: 840px" TabIndex="17"></asp:TextBox>

    <asp:TextBox ID="Txtwphn" runat="server" Style="z-index: 116; left: 496px; position: absolute;

    top: 840px" TabIndex="16"></asp:TextBox>

    <asp:TextBox ID="Txtzipcod" runat="server" Style="z-index: 117; left: 912px; position: absolute;

    top: 304px" TabIndex="7"></asp:TextBox>

    <asp:TextBox ID="Txtadd" runat="server" Height="56px" Style="z-index: 118; left: 496px;

    position: absolute; top: 304px" TextMode="MultiLine" Width="176px" TabIndex="6"></asp:TextBox>

    <asp:TextBox ID="Txtfname" runat="server" Style="z-index: 119; left: 912px; position: absolute;

    top: 208px" TabIndex="2"></asp:TextBox>

    <asp:TextBox ID="Txtlname" runat="server" Style="z-index: 120; left: 496px; position: absolute;

    top: 208px" TabIndex="1"></asp:TextBox>

    <asp:TextBox ID="Txtempid" runat="server" Style="z-index: 121; left: 496px; position: absolute;

    top: 160px"></asp:TextBox>

    <asp:TextBox ID="Txtemail" runat="server" Style="z-index: 122; left: 912px; position: absolute;

    top: 896px" TabIndex="19"></asp:TextBox>

    &nbsp;

    <asp:DropDownList ID="Ddstate" runat="server" Style="z-index: 123; left: 832px;

    position: absolute; top: 400px" AutoPostBack="True" Width="120px" TabIndex="9">

    </asp:DropDownList>

    &nbsp;

    <asp:DropDownList ID="ddcnt" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2"

    Style="z-index: 124; left: 496px; position: absolute; top: 400px" Width="155px" DataTextField="cntname" DataValueField="cntid" TabIndex="8" Height="22px">

    </asp:DropDownList>

    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:blmw_empdirConnectionString %>"

    SelectCommand="SELECT * FROM [tbcnt]"></asp:SqlDataSource>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:blmw_empdirConnectionString %>"

    SelectCommand="SELECT * FROM [tbdept]"></asp:SqlDataSource>

    &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;

    <asp:Label ID="Lbldob" runat="server" Height="19px" Style="z-index: 125; left: 320px;

    position: absolute; top: 256px" Text="Date Of Birth" Width="128px"></asp:Label>

    &nbsp; &nbsp;

    <asp:DropDownList ID="Ddyear" runat="server" AutoPostBack="True" Style="z-index: 126;

    left: 648px; position: absolute; top: 256px" Width="56px" TabIndex="5">

    </asp:DropDownList>

    <asp:DropDownList ID="Ddmonth" runat="server" Style="z-index: 127; left: 568px; position: absolute;

    top: 256px" Width="56px" TabIndex="4" AutoPostBack="True">

    </asp:DropDownList>

    <asp:DropDownList ID="Dddate" runat="server" AutoPostBack="True" Style="z-index: 128;

    left: 496px; position: absolute; top: 256px" Width="48px" TabIndex="3">

    </asp:DropDownList>

    &nbsp;&nbsp;

    <asp:FileUpload ID="FileUpload1" runat="server" Style="z-index: 129; left: 496px;

    position: absolute; top: 960px" />

    &nbsp;

    <asp:Label ID="Lblshift" runat="server" Height="19px" Style="z-index: 130; left: 320px;

    position: absolute; top: 784px" Text="Shift" Width="128px"></asp:Label>

    <asp:Label ID="Lblsal" runat="server" Height="19px" Style="z-index: 131; left: 320px;

    position: absolute; top: 728px" Text="Salary" Width="128px"></asp:Label>

    <asp:Label ID="Lbljobdesc" runat="server" Height="19px" Style="z-index: 132; left: 320px;

    position: absolute; top: 592px" Text="Description Of Job" Width="128px"></asp:Label>

    <asp:Label ID="Lbljobtit" runat="server" Height="19px" Style="z-index: 133; left: 320px;

    position: absolute; top: 528px" Text="Job Title" Width="128px"></asp:Label>

    <asp:Label ID="Lbldept" runat="server" Height="19px" Style="z-index: 134; left: 320px;

    position: absolute; top: 464px" Text="Department" Width="128px"></asp:Label>

    <asp:TextBox ID="TxtJobDesc" runat="server" Height="80px" Style="z-index: 135; left: 496px;

    position: absolute; top: 592px" TabIndex="13" TextMode="MultiLine" Width="440px"></asp:TextBox>

    <asp:TextBox ID="TxtJobTit" runat="server" Height="22px" Style="z-index: 136; left: 496px;

    position: absolute; top: 528px" TabIndex="12" Width="155px"></asp:TextBox>

    <asp:DropDownList ID="Ddshift" runat="server" AutoPostBack="True"

    Style="z-index: 137; left: 496px; position: absolute; top: 784px" Width="155px" DataTextField="cntname" DataValueField="cntid" TabIndex="15" Height="22px">

    </asp:DropDownList>

    <asp:DropDownList ID="Ddsal" runat="server" AutoPostBack="True"

    Style="z-index: 138; left: 496px; position: absolute; top: 728px" Width="155px" DataTextField="cntname" DataValueField="cntid" TabIndex="14" Height="22px">

    </asp:DropDownList>

    <asp:DropDownList ID="Dddept" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"

    Style="z-index: 139; left: 496px; position: absolute; top: 464px" Width="155px" DataTextField="dept" DataValueField="deptid" TabIndex="11" Height="22px">

    </asp:DropDownList>

     

    <asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#999999"

    BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" Style="z-index: 140;

    left: -54px; position: absolute; top: 1144px" AutoGenerateColumns="False" AllowPaging ="true" AllowSorting ="true" Width="1152px" Height="152px" TabIndex="17" >

    <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />

    <RowStyle BackColor="#EEEEEE" ForeColor="Black" />

    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />

    <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />

    <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />

    <AlternatingRowStyle BackColor="Gainsboro" />

    <Columns >

    <asp:BoundField DataField ="empid" HeaderText ="Employee ID" ControlStyle-Width="10px"/>

    <asp:BoundField DataField ="lname" HeaderText ="Last Name" />

    <asp:BoundField DataField ="fname" HeaderText =" First Name" />

    <asp:BoundField DataField ="dob" HeaderText ="Date Of Birth" />

    <asp:BoundField DataField ="addr" HeaderText =" Address" />

    <asp:BoundField DataField ="city" HeaderText ="City" />

    <asp:BoundField DataField ="statename" HeaderText ="State" />

    <asp:BoundField DataField ="cntname" HeaderText ="Country" />

    <asp:BoundField DataField ="zipcode" HeaderText ="Zipcode" />

    <asp:BoundField DataField ="dept" HeaderText ="Department" />

    <asp:BoundField DataField ="job_tit" HeaderText ="Job Title" />

    <asp:BoundField DataField ="job_desc" HeaderText="Job Description" />

    <asp:BoundField DataField ="w_phone" HeaderText ="Work Phone" />

    <asp:BoundField DataField ="c_phone" HeaderText ="Cell Phone" />

    <asp:BoundField DataField ="email" HeaderText ="Email ID" />

    <asp:BoundField DataField ="fax" HeaderText ="Fax" />

    <asp:ImageField DataImageUrlField ="photo" ControlStyle-Width ="110px" ControlStyle-Height ="120px"></asp:ImageField>

    <asp:TemplateField HeaderText ="Select">

    <ItemTemplate >

    <asp:LinkButton ID ="lk" runat ="server" CommandName ="Select" Text ="Select">

    </asp:LinkButton>

    </ItemTemplate>

    </asp:TemplateField>

     

    </Columns>

    <PagerSettings Mode="NextPreviousFirstLast" />

    </asp:GridView><asp:Button ID="Btnupd" runat="server" Style="z-index: 141; left: 528px; position: absolute;

    top: 1072px" Text="Update" Width="104px" TabIndex="16" />

     

    </asp:Content>

     

     

  • Re: Displaying Selected Value in Dropdown list

    07-09-2008, 8:53 AM
    • Star
      11,863 point Star
    • shahed.kazi
    • Member since 07-09-2008, 2:15 AM
    • Sydney, Australia
    • Posts 2,330

     You need to update the method
    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged

    to contain like

    DropDownList1.SelectedIndex = GridView1.SelectedIndex; 

    This line basically sets the selectedIndex of DropDownList to the selectedIndex of GridView.  

  • Re: Displaying Selected Value in Dropdown list

    07-09-2008, 9:02 AM
    • Member
      34 point Member
    • schauhan13
    • Member since 07-08-2008, 7:15 PM
    • Posts 158

    dropdownlist1.selectedindex= gridview1.selectedindex

    it is not working properly because for my first row it shows none. so logic is not working

  • Re: Displaying Selected Value in Dropdown list

    07-09-2008, 9:06 AM
    • Star
      11,863 point Star
    • shahed.kazi
    • Member since 07-09-2008, 2:15 AM
    • Sydney, Australia
    • Posts 2,330

     You need to substitute "dropdownlist1" & "gridview1" with the id's of the related dropdownlist & gridview you are using.

  • Re: Displaying Selected Value in Dropdown list

    07-09-2008, 9:24 AM
    • Member
      34 point Member
    • schauhan13
    • Member since 07-08-2008, 7:15 PM
    • Posts 158

    i did that but if second row of gridview is selected its index will be 1 but country selected's index is let say 5 so it will give wrong answer

  • Re: Displaying Selected Value in Dropdown list

    07-11-2008, 3:14 AM
    Answer

    Hi schauhan13,

    Try this:

    ddcnt.Text = GridView1.SelectedRow.Cells(7).Text

    Thanks,

    Qin Dian Tang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (12 items)