Hi, there. I am new in .Net and am seeking urgent help, please.
I need to control the display in the data grid according to the selection in the dropdown list. how can I do that??

Recommended Answers

All 2 Replies

the easiest way to do this would be to create a new fill method for the DataTable that controls your datagrid. In this fill method set a user defined variable. Then you can use the selected Value from your ComboBox to select that defined variable. Then it is just a matter of refreshing and you are set.

hope this helps but in case it doesn't it is probably a good idea to post a sample of the code so it might be easier to help you.

Here's my code , please i do need help

myda = New SqlDataAdapter("Select Distinct COUNTRY from FO_TestingLines_TBL order by COUNTRY", ConfigurationSettings.AppSettings("myconnection"))
ds = New DataSet()
myda.Fill(ds, "AllTables")
OPERATOR.Visible = True
COUNTRY.DataSource = ds.Tables(0)
COUNTRY.DataTextField = ds.Tables(0).Columns("COUNTRY").ColumnName.ToString()
COUNTRY.DataValueField = ds.Tables(0).Columns("COUNTRY").ColumnName.ToString()
COUNTRY.DataBind()
COUNTRY.Items.Insert(0, "<--Select a Country-->")
Session("testing") = "FO_TestingLines_TBL"

End Sub
Public Sub Country_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
myda3 = New SqlDataAdapter("Select DISTINCT OPERATOR from " & Session("testing") & " where COUNTRY ='" & COUNTRY.SelectedItem.Value & "' order by OPERATOR", ConfigurationSettings.AppSettings("myconnection"))
ds3 = New DataSet()
myda3.Fill(ds3, "Tables")
OPERATOR.DataSource = ds3.Tables(0)
OPERATOR.DataTextField = ds3.Tables(0).Columns("OPERATOR").ColumnName.ToString()
OPERATOR.DataValueField = ds3.Tables(0).Columns("OPERATOR").ColumnName.ToString()
OPERATOR.DataBind()
OPERATOR.Items.Insert(0, "<--Select an Operator-->")
OPERATOR.Visible = True
DataGrid1.Visible = False


End Sub
Public Sub Operator_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
myda6 = New SqlDataAdapter("Select ICCID,IMSI,MSISDN,PIN,PUK,PIN2,PUK2,Active,[GPRS Services],[Description],Remark from " & Session("testing") & " where COUNTRY ='" & COUNTRY.SelectedItem.Value & "' and OPERATOR = '" & OPERATOR.SelectedItem.Value & "' ", ConfigurationSettings.AppSettings("myconnection"))
ds6 = New DataSet()
myda6.Fill(ds6, "FO_TestingLines_TBL")
DataGrid1.DataSource = ds6.Tables(0)
DataGrid1.DataBind()
DataGrid1.Visible = True
DataGrid1.CellSpacing() = 2


End Sub
Private Sub updtcountry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Session("infcountry") = COUNTRY.SelectedItem.Value
Response.Redirect("updtct.aspx")
End Sub
Private Sub updtoprinfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Session("infcountry") = COUNTRY.SelectedItem.Value
Session("infopr") = OPERATOR.SelectedItem.Value
Response.Redirect("uptoprinf.aspx")
End Sub
Private Sub updsim_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updsim.Click
Session("infcountry") = COUNTRY.SelectedItem.Value
Session("infopr") = OPERATOR.SelectedItem.Value
Response.Redirect("uptsim.aspx")
End Sub

Public Sub TESTLINES_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TESTLINES.SelectedIndexChanged
If TESTLINES.SelectedItem.Value = "MTC touch Testing Lines" Then
myda5 = New SqlDataAdapter("Select GSMNUMBERS, TYPE, GPRSMMS, REMARKS from MTC_TESTLINE_TBL where COUNTRY ='" & COUNTRY.SelectedItem.Value & "' and OPERATOR = '" & OPERATOR.SelectedItem.Value & "'", ConfigurationSettings.AppSettings("myconnection"))
ds5 = New DataSet()
myda5.Fill(ds5, "MTC_TESTLINE_TBL")
DataGrid1.DataSource = ds5.Tables(0)
DataGrid1.DataBind()
DataGrid1.Visible = True
DataGrid1.CellSpacing() = 2
End If

If TESTLINES.SelectedItem.Value = "FO Testing Lines" Then
myda6 = New SqlDataAdapter("Select ICCID,IMSI,MSISDN,PIN,PUK,PIN2,PUK2,Active,[GPRS Services],[Description],Remark from FO_TestingLines_TBL where COUNTRY ='" & COUNTRY.SelectedItem.Value & "' and OPERATOR = '" & OPERATOR.SelectedItem.Value & "'", ConfigurationSettings.AppSettings("myconnection"))
ds6 = New DataSet()
myda6.Fill(ds6, "FO_TestingLines_TBL")
DataGrid1.DataSource = ds6.Tables(0)
DataGrid1.DataBind()
DataGrid1.Visible = True
DataGrid1.CellSpacing() = 2
End If
End Sub


End Class

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.