A DropDownList control updating Gridview Control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi folks,
A web form has a DropDownList control and GridView control. Both are
data binding. I expect that selecting an item in the DrowDownList will
update the GridView visually. But, extra step is necessary by selecting any
item in the gridview, the gridview then refreshes. the related C# code as
below:

protected void DropDownList1_SelectedIndexChanged(...)
{ VideoGridView.DataBind(); }
Please advise. Thanks.
PeterK
 
Hopefully that would help you. i am working vb.net



Dim myConnection As New
SqlConnection(ConfigurationManager.ConnectionStrings("ResTrack").Connect
ionString)
If Not IsPostBack Then
Dim CmdPosition As SqlCommand = myConnection.CreateCommand()
CmdPosition.CommandType = CommandType.Text
CmdPosition.CommandText = "SELECT Position_ID,
Position_Title FROM position"
Dim ds As DataSet = New DataSet
Dim da As SqlDataAdapter = New SqlDataAdapter
da.SelectCommand = CmdPosition
da.Fill(ds, "position")
With Position_Title
.DataSource = ds.Tables("position")
.DataTextField = "Position_Title"
.DataValueField = "Position_ID"
.DataBind()
End With
Else
Dim CmdApplicants As SqlCommand = myConnection.CreateCommand
CmdApplicants.CommandType = CommandType.Text
CmdApplicants.CommandText = "Select * From Applicant"
Dim daApplicant As New SqlDataAdapter
Dim dsApplicant As New DataSet
daApplicant.SelectCommand = CmdApplicants
daApplicant.Fill(dsApplicant, "applicant")
'create dataview
Dim DV As New DataView(dsApplicant.Tables("applicant"))
DV.RowFilter = "Position_ID = '" & _
Position_Title.SelectedItem.Value & "'"
View_Applicants.DataSource = DV
View_Applicants.DataBind()
End If
End Sub
 
Dim myConnection As New
SqlConnection(ConfigurationManager.ConnectionStrings("ResTrack").Connect
ionString)
If Not IsPostBack Then
Dim CmdPosition As SqlCommand = myConnection.CreateCommand()
CmdPosition.CommandType = CommandType.Text
CmdPosition.CommandText = "SELECT Position_ID,
Position_Title FROM position"
Dim ds As DataSet = New DataSet
Dim da As SqlDataAdapter = New SqlDataAdapter
da.SelectCommand = CmdPosition
da.Fill(ds, "position")
With Position_Title
.DataSource = ds.Tables("position")
.DataTextField = "Position_Title"
.DataValueField = "Position_ID"
.DataBind()
End With
Else
Dim CmdApplicants As SqlCommand = myConnection.CreateCommand
CmdApplicants.CommandType = CommandType.Text
CmdApplicants.CommandText = "Select * From Applicant"
Dim daApplicant As New SqlDataAdapter
Dim dsApplicant As New DataSet
daApplicant.SelectCommand = CmdApplicants
daApplicant.Fill(dsApplicant, "applicant")
'create dataview
Dim DV As New DataView(dsApplicant.Tables("applicant"))
DV.RowFilter = "Position_ID = '" & _
Position_Title.SelectedItem.Value & "'"
View_Applicants.DataSource = DV
View_Applicants.DataBind()
End If
End Sub
 
Back
Top