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.IOPartial Class Administrator_EmpUpd
Inherits System.Web.UI.PageDim con As New SqlConnection(ConfigurationManager.ConnectionStrings("cn").ConnectionString)
Dim cmd As New SqlCommandProtected 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.Textcmd.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.SelectedValuecmd.Parameters.Add("@zp", SqlDbType.Int).Value = Txtzipcod.Text
cmd.Parameters.Add(
"@ph", SqlDbType.VarChar).Value = "~/images/" & FileUpload1.FileNamecmd.Parameters.Add("@did", SqlDbType.Int).Value = Convert.ToString(Dddept.SelectedValue)
cmd.Parameters.Add(
"@jt", SqlDbType.VarChar).Value = TxtJobTit.Textcmd.Parameters.Add("@jd", SqlDbType.VarChar).Value = TxtJobDesc.Text
cmd.Parameters.Add(
"@sl", SqlDbType.VarChar).Value = Ddsal.SelectedValuecmd.Parameters.Add("@st", SqlDbType.VarChar).Value = Ddshift.SelectedValue
cmd.Parameters.Add(
"@wf", SqlDbType.NVarChar).Value = Txtwphn.Textcmd.Parameters.Add("@cf", SqlDbType.NVarChar).Value = Txtcphn.Text
cmd.Parameters.Add(
"@em", SqlDbType.NVarChar).Value = Txtemail.Textcmd.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 SubPrivate 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 SubProtected 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 SubProtected 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 SubProtected 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 SubPrivate 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 WithDim i As Integer = 1935
Dim n As Integer = 2009While i < n
Ddyear.Items.Add(i)
i = i + 1
End WhileDim j As Integer = 1
Dim m As Integer = 31While j <= m
Dddate.Items.Add(j)
j = j + 1
End While
End SubProtected 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>
<asp:DropDownList ID="Ddstate" runat="server" Style="z-index: 123; left: 832px;
position: absolute; top: 400px"
AutoPostBack="True" Width="120px" TabIndex="9">
</asp:DropDownList>
<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>
<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>
<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>
<asp:FileUpload ID="FileUpload1" runat="server" Style="z-index: 129; left: 496px;
position: absolute; top: 960px"
/>
<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>