在c#.net中级联DataGridViewComboBoxColumn [英] cascading DataGridViewComboBoxColumn in c# .net

查看:90
本文介绍了在c#.net中级联DataGridViewComboBoxColumn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好....

我在datagridview中有三个组合框。有国家,州和城市。当我选择国家,然后根据国家/地区状态组合框负载。类似城市...所有组合框填充来自sql。

解决方案

你可以使用ajax auto complete extender为文本框看起来像下拉列表..



1.在网格视图中添加自动编辑扩展器编辑项目模板



< asp:textbox runat =serverid =txtStateautopostback =truecssclass =txtClassxmlns:asp =#unknown>





< asp:autocompleteextender id =AutoDepartmentFromrunat =serverdelimitercharacters =xmlns :asp =#unknown>

Enabled =TrueServicePath =MinimumPrefixLength =0ServiceMethod =GetCompletionList

ContextKey =StateUseContextKey =TrueCompletionListElementID =Div1

TargetControlID =txtStateCompletionInterval =100EnableCaching =true>





2.添加服务方式在代码behinde服务此文本框

< system.web.services.webmethod()> _ $ / $
共享函数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)

返回ItemArray

结束函数

如果你按A然后它会列出从A开始的状态名称。


写一个函数来添加查询

公共函数GetIntelligenceList (ByVal prefixText As String,ByVal contextKey As String)As String()

Dim ColumnName As String = String.Empty



Dim items As新列表(字符串)

Dim sqlquery As String = String.Empty

Dim Count As Integer = 0



尝试

'根据登录用户的类型从表中提取的值

如果contextKey =state那么

sqlquery =从状态中选择Top 10 stateName,其中stateName就像''& prefixText& %'

ColumnName =MachineId

结束如果

如果contextKey =DrawingNo那么

sqlquery =从city所在的cityName中选择cityName& prefixText& %'

ColumnName =DrawingNo

结束如果



Dim AdptCompleteList As New SqlDataAdapter(sqlquery) ,CMScn)

Dim dtFilteredList As New DataTable



'在数据表中填写查询结果

AdptCompleteList.Fill (dtFilteredList)

Dim itemList As String



'AssogestionList从datatable存储到名为itemList的数组

Dim Dr As DataRow

For each dr in dtFilteredList.Rows

itemList = dr(ColumnName).ToString()

items.Add(itemList)

点数+ = 1

下一页

返回items.ToArray()

Catch ex As Exception

WriteToLog(MachineDispatch页面 - 机器日志的自动扩展器:& ex.To String())

什么都不返回

结束尝试

结束功能

3.Text Change状态调用事件城市


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.

解决方案

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


这篇关于在c#.net中级联DataGridViewComboBoxColumn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆