Click here to Skip to main content
15,922,155 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all....
I've three combobox in datagridview. There are Country,State and City.when i select country then state combobox load based on country. similarly city... all combobox fill from sql.
Posted
Comments
Shafeequl 1-Jul-13 2:37am    
you can have this by using cellvalue changed event in dataridview...
How is your db design??may be i can help you..

1 solution

You can use ajax auto complete extender for the text box that will look like drop down list..

1. Add auto comlete extender in the grid view inside Edit Item template

<asp:textbox runat="server" id="txtState" autopostback="true" cssclass="txtClass" xmlns:asp="#unknown">


<asp:autocompleteextender id="AutoDepartmentFrom" runat="server" delimitercharacters="" xmlns:asp="#unknown">
Enabled="True" ServicePath="" MinimumPrefixLength="0" ServiceMethod="GetCompletionList"
ContextKey="State" UseContextKey="True" CompletionListElementID="Div1"
TargetControlID="txtState" CompletionInterval="100" EnableCaching="true">


2.Add a service method in the code behinde to serve this text box
<system.web.services.webmethod()> _
Shared Function GetCompletionList(ByVal prefixText As String, ByVal contextKey As String) As String()
Dim Obj As New CriticalIndentRequirement
Dim ItemArray As String()
ItemArray = Obj.GetIntelligenceList(prefixText, contextKey)
Return ItemArray
End Function
if you press A then it will list the names of the states which starts from A

write a function to add query
Public Function GetIntelligenceList(ByVal prefixText As String, ByVal contextKey As String) As String()
Dim ColumnName As String = String.Empty

Dim items As New List(Of String)
Dim sqlquery As String = String.Empty
Dim Count As Integer = 0

Try
'Values extracted from tables based on type of user logged in
If contextKey = "state" Then
sqlquery = "select Top 10 stateName from state where stateName like '" & prefixText & "%'"
ColumnName = "MachineId"
End If
If contextKey = "DrawingNo" Then
sqlquery = "select cityName from city where cityName like '" & prefixText & "%'"
ColumnName = "DrawingNo"
End If

Dim AdptCompleteList As New SqlDataAdapter(sqlquery, CMScn)
Dim dtFilteredList As New DataTable

'Fill query result in a datatable
AdptCompleteList.Fill(dtFilteredList)
Dim itemList As String

'SuggestionList stored from datatable to an array called itemList
Dim dr As DataRow
For Each dr In dtFilteredList.Rows
itemList = dr(ColumnName).ToString()
items.Add(itemList)
Count += 1
Next
Return items.ToArray()
Catch ex As Exception
WriteToLog("MachineDispatch Page - Autoextender for Machine Log: " & ex.ToString())
Return Nothing
End Try
End Function
3.Text Change Event of state call city
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900