I have a drop list in gridview In which I am selecting a data in dropdown list from database like this
Adeel
Akram
Ali
Asif
Zeeshan
Problem is that when gridview loads for example with 5 rows for data inserting the data shows in drop down is sorted in such a way the on each row first element is adeel but I want to sort the names according row For Example In first row the element should show as adeel and in second row value should show as Akram and so on.Below is my code in which I am using to load griview for data inserting
For Each gvRow As GridViewRow In GridView1.Rows
Dim ddlEmpCode As DropDownList = CType(gvRow.FindControl("DropDownlist1"), DropDownList)
Dim con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("DatabaseConnectionString2").ConnectionString)
Dim cmd As SqlCommand = New SqlCommand("insert into Status(m_date,emp_code) values (@m_Date,@EMp_Code)", con)
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("m_Date", txtdate.Text)
cmd.Parameters.AddWithValue("Animal_Code", ddlAnimalCode.SelectedValue)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
Label1.Text = "All Records are Saved Successfully"
btnInsert.Enabled = False
Next
Try the following code..try to set the selected index of dropdown in rowdatabound event as follow…
**I have written this in C#,u need to write the same in Vb