I have a Situation, where in a DataGrid on ASP.Net page, on Edit
Command Button, I have to provide a combo box in a column to choose
values from this combo for Editing the row. I have created a
dynamicUserCombo class which implements ITemplate.
The situation is that I have a table with CustomerName,
CustomerFullName and City and the datagrid showing all three columns.
The Combo should display CustomeFullName, with the beneath value of
CustomerName.
When I bind this combo to the table it works fine and get me all the
records in the combo.. but the problem is that I want to put a
condition in Table's Select query on the basis of current row "City"
of datagrid. The combo should display only Customers of the City of
Current Row (being edited)
Can you please help, how to achieve this filter on the basis of current
row..
The code is given below
Thanks and regards,
Damroo
---
Public Class dynamicUserCombo
Implements ITemplate
Public templateType As ListItemType
Public columnName As String
Public Overridable Overloads Sub InstantiateIn(ByVal container As
System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
Select Case templateType
Case ListItemType.EditItem
Dim ocb_user As DropDownList = New DropDownList
'The problem is how to get city of the current row here
ocb_user.DataSource = BindCombo(city)
ocb_user.DataTextField = "fullname"
ocb_user.DataValueField = "name"
container.Controls.Add(ocb_user)
End Select
End Sub
Public Function BindCombo(ByVal city as string) As DataView
Dim mysql As String = "Select name, type from mytable where city ='" &
city & "'"
' It works fine when I dont have the condition..
Dim objDV As DataView
Try
objDV = DBModule.ExecuteQuery(mysql)
BindCombo = objDV
Catch ex As Exception
End Try
End Function
End Class