Hi,
I have a RadGrid that binds using NeedDataSource. The NeedDataSource calls a tableadapter that uses a combobox SelectedValue as an input parameter. So the grid is populated based on the SelectedValue.
That works fine when the page first loads. Though I am having issues with when I change a combobox SelectedValue.
I believe it is a matter of the event ordering. As in the NeedDataSource kicks off BEFORE the SelectedIndexChanged is fired.
Below is my RadGrid:
<
telerik:RadGrid
ID
=
"RDHauls"
runat
=
"server"
AutoGenerateEditColumn
=
"True"
GridLines
=
"Horizontal"
AutoGenerateColumns
=
"False"
AlternatingItemStyle-BackColor
=
"#ecf3f4"
BorderColor
=
"#28899A"
EditItemStyle-BackColor
=
"#009999"
EditItemStyle-Font-Bold
=
"true"
OnItemDataBound
=
"RDHauls_ItemDataBound"
OnItemCreated
=
"RDHauls_ItemCreated"
OnNeedDataSource
=
"RDHauls_NeedDataSource"
CssClass
=
"Radgrid"
>
<
AlternatingItemStyle
BackColor
=
"#ECF3F4"
></
AlternatingItemStyle
>
<
HeaderStyle
BorderColor
=
"#28899A"
Font-Bold
=
"True"
Font-Size
=
"12px"
Font-Names
=
"Verdana"
/>
<
MasterTableView
EnableViewState
=
"false"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"TripCode"
FilterControlAltText
=
"Filter TripCode column"
HeaderText
=
"Trip Code"
SortExpression
=
"TripCode"
UniqueName
=
"TripCode"
ReadOnly
=
"true"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"VessReg"
FilterControlAltText
=
"Filter VessReg column"
HeaderText
=
"Vessel"
SortExpression
=
"VessReg"
UniqueName
=
"VessReg"
ReadOnly
=
"true"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"HaulNumber"
HeaderText
=
"Haul"
UniqueName
=
"HaulNumber"
ReadOnly
=
"true"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"RigNumber"
HeaderText
=
"Rig"
UniqueName
=
"RigNumber"
ReadOnly
=
"true"
></
telerik:GridBoundColumn
>
<
telerik:GridDropDownColumn
DataField
=
"Technique"
HeaderText
=
"Technique"
ListTextField
=
"Name"
ListValueField
=
"Code"
UniqueName
=
"Technique"
ColumnEditorID
=
"Technique"
Visible
=
"false"
DropDownControlType
=
"DropDownList"
></
telerik:GridDropDownColumn
>
<
telerik:GridCheckBoxColumn
DataField
=
"HaulSampledTrueFalse"
HeaderText
=
"Haul Sampled?"
Visible
=
"false"
UniqueName
=
"HaulSampledTrueFalse"
ColumnEditorID
=
"HaulSampled"
></
telerik:GridCheckBoxColumn
>
<
telerik:GridCheckBoxColumn
DataField
=
"TowDisruptedTrueFalse"
HeaderText
=
"Tow Disrupted?"
Visible
=
"false"
UniqueName
=
"TowDisruptedTrueFalse"
></
telerik:GridCheckBoxColumn
>
<
telerik:GridBoundColumn
DataField
=
"CodEnd"
HeaderText
=
"Cod End (mm)"
UniqueName
=
"CodEnd"
ColumnEditorID
=
"CodEnd"
Visible
=
"false"
ConvertEmptyStringToNull
=
"true"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"MeshSize"
HeaderText
=
"Mesh Size (mm)"
UniqueName
=
"MeshSize"
Visible
=
"false"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"SelectivityMesh"
HeaderText
=
"Selectivity Mesh (mm)"
UniqueName
=
"SelectivityMesh"
Visible
=
"false"
></
telerik:GridBoundColumn
>
<
telerik:GridDropDownColumn
DataField
=
"TwineCode"
HeaderText
=
"Twine"
ListTextField
=
"Name"
ListValueField
=
"Code"
UniqueName
=
"TwineCode"
ColumnEditorID
=
"TwineCode"
Visible
=
"false"
DropDownControlType
=
"DropDownList"
></
telerik:GridDropDownColumn
>
<
telerik:GridBoundColumn
DataField
=
"TwineThickness"
HeaderText
=
"Twine Thickness (mm)"
UniqueName
=
"TwineThickness"
Visible
=
"false"
DataType
=
"System.Decimal"
></
telerik:GridBoundColumn
>
<
telerik:GridDropDownColumn
DataField
=
"GroundGear"
HeaderText
=
"Ground Gear"
ListTextField
=
"Name"
ListValueField
=
"Code"
UniqueName
=
"GroundGear"
ColumnEditorID
=
"GroundGear"
Visible
=
"false"
DropDownControlType
=
"DropDownList"
></
telerik:GridDropDownColumn
>
<
telerik:GridBoundColumn
DataField
=
"Bridal"
HeaderText
=
"Bridal (m)"
UniqueName
=
"Bridal"
Visible
=
"false"
DataType
=
"System.Int32"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"HeadlineHeight"
HeaderText
=
"Headline Height (m)"
UniqueName
=
"HeadlineHeight"
Visible
=
"false"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"WarpLength"
HeaderText
=
"Warp Length (fath)"
UniqueName
=
"WarpLength"
Visible
=
"false"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"DoorSpread"
HeaderText
=
"Door Spread (m)"
UniqueName
=
"DoorSpread"
Visible
=
"false"
></
telerik:GridBoundColumn
>
<
telerik:GridDropDownColumn
DataField
=
"TidalStateCode"
HeaderText
=
"Tidal State"
ListTextField
=
"Name"
ListValueField
=
"Code"
UniqueName
=
"TidalStateCode"
ColumnEditorID
=
"TidalStateCode"
Visible
=
"false"
DropDownControlType
=
"DropDownList"
></
telerik:GridDropDownColumn
>
<
telerik:GridDropDownColumn
DataField
=
"TidalStrengthCode"
HeaderText
=
"Tidal Strength"
ListTextField
=
"Name"
ListValueField
=
"Code"
UniqueName
=
"TidalStrengthCode"
ColumnEditorID
=
"TidalStrengthCode"
Visible
=
"false"
DropDownControlType
=
"DropDownList"
></
telerik:GridDropDownColumn
>
<
telerik:GridDropDownColumn
DataField
=
"TidalDirectionCode"
HeaderText
=
"Tidal Direction"
ListTextField
=
"Name"
ListValueField
=
"Code"
UniqueName
=
"TidalDirectionCode"
ColumnEditorID
=
"TidalDirectionCode"
Visible
=
"false"
DropDownControlType
=
"DropDownList"
></
telerik:GridDropDownColumn
>
<
telerik:GridBoundColumn
DataField
=
"GroundSpeed"
HeaderText
=
"Speed Over Ground (kts)"
UniqueName
=
"GroundSpeed"
Visible
=
"false"
DataType
=
"System.Decimal"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"ShotDate"
HeaderText
=
"Shot Date"
UniqueName
=
"ShotDate"
Visible
=
"false"
>
<
ColumnValidationSettings
EnableRequiredFieldValidation
=
"True"
>
<
RequiredFieldValidator
ID
=
"RFShotDate"
Font-Bold
=
"True"
> Enter Shot date</
RequiredFieldValidator
>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridDropDownColumn
DataField
=
"ShotTime"
HeaderText
=
"Shot Time"
ListTextField
=
"vchTime"
ListValueField
=
"vchTime"
UniqueName
=
"ShotTime"
ColumnEditorID
=
"ShotTime"
Visible
=
"false"
DropDownControlType
=
"DropDownList"
></
telerik:GridDropDownColumn
>
<
telerik:GridBoundColumn
DataField
=
"ShotDepth"
HeaderText
=
"Shot Depth (fath)"
UniqueName
=
"ShotDepth"
Visible
=
"false"
DataType
=
"System.Decimal"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"ShotLatd"
HeaderText
=
"Shot Latitude (deg)"
UniqueName
=
"ShotLatd"
Visible
=
"false"
>
<
ColumnValidationSettings
EnableRequiredFieldValidation
=
"True"
>
<
RequiredFieldValidator
ID
=
"RFShotLatitudeD"
Font-Bold
=
"True"
> Enter Shot Latitude (deg)</
RequiredFieldValidator
>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"ShotLatm"
HeaderText
=
"Shot Latitude (min)"
UniqueName
=
"ShotLatm"
Visible
=
"false"
>
<
ColumnValidationSettings
EnableRequiredFieldValidation
=
"True"
>
<
RequiredFieldValidator
ID
=
"RFShotLatitudeM"
Font-Bold
=
"True"
> Enter Shot Latitude (min)</
RequiredFieldValidator
>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"ShotLond"
HeaderText
=
"Shot Longitude (deg)"
UniqueName
=
"ShotLond"
Visible
=
"false"
>
<
ColumnValidationSettings
EnableRequiredFieldValidation
=
"True"
>
<
RequiredFieldValidator
ID
=
"RFShotLongitudeD"
Font-Bold
=
"True"
> Enter Shot Longitude (deg)</
RequiredFieldValidator
>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"ShotLonm"
HeaderText
=
"Shot Longitude (min)"
UniqueName
=
"ShotLonm"
Visible
=
"false"
>
<
ColumnValidationSettings
EnableRequiredFieldValidation
=
"True"
>
<
RequiredFieldValidator
ID
=
"RFShotLongitudeM"
Font-Bold
=
"True"
> Enter Shot Longitude (min)</
RequiredFieldValidator
>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
UniqueName
=
"ShotEastWest"
ColumnEditorID
=
"ShotEastWest"
HeaderText
=
"Shot East/West"
Visible
=
"false"
>
<
ItemTemplate
>
<%# Eval("ShotEW")%>
</
ItemTemplate
>
<
EditItemTemplate
>
<
asp:RadioButtonList
ID
=
"rdShotEastWest"
runat
=
"server"
RepeatDirection
=
"Horizontal"
>
<
asp:ListItem
Text
=
"East"
Value
=
"2"
></
asp:ListItem
>
<
asp:ListItem
Text
=
"West"
Value
=
"1"
></
asp:ListItem
>
</
asp:RadioButtonList
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
DataField
=
"HaulDate"
HeaderText
=
"Haul Date"
UniqueName
=
"HaulDate"
Visible
=
"false"
>
<
ColumnValidationSettings
EnableRequiredFieldValidation
=
"True"
>
<
RequiredFieldValidator
ID
=
"RFHaulDate"
Font-Bold
=
"True"
> Enter Haul date</
RequiredFieldValidator
>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridDropDownColumn
DataField
=
"HaulTime"
HeaderText
=
"Haul Time"
ListTextField
=
"vchTime"
ListValueField
=
"vchTime"
UniqueName
=
"HaulTime"
ColumnEditorID
=
"HaulTime"
Visible
=
"false"
DropDownControlType
=
"DropDownList"
></
telerik:GridDropDownColumn
>
<
telerik:GridBoundColumn
DataField
=
"HaulDepth"
HeaderText
=
"Haul Depth (fath)"
UniqueName
=
"HaulDepth"
Visible
=
"false"
DataType
=
"System.Decimal"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"HaulLatd"
HeaderText
=
"Haul Latitude (deg)"
UniqueName
=
"HaulLatd"
Visible
=
"false"
>
<
ColumnValidationSettings
EnableRequiredFieldValidation
=
"True"
>
<
RequiredFieldValidator
ID
=
"RFHaulLatitudeD"
Font-Bold
=
"True"
> Enter Haul Latitude (deg)</
RequiredFieldValidator
>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"HaulLatm"
HeaderText
=
"Haul Latitude (min)"
UniqueName
=
"HaulLatm"
Visible
=
"false"
>
<
ColumnValidationSettings
EnableRequiredFieldValidation
=
"True"
>
<
RequiredFieldValidator
ID
=
"RFHaulLatitudeM"
Font-Bold
=
"True"
> Enter Haul Latitude (min)</
RequiredFieldValidator
>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"HaulLond"
HeaderText
=
"Haul Longitude (deg)"
UniqueName
=
"HaulLond"
Visible
=
"false"
>
<
ColumnValidationSettings
EnableRequiredFieldValidation
=
"True"
>
<
RequiredFieldValidator
ID
=
"RFHaulLongitudeD"
Font-Bold
=
"True"
> Enter Haul Longitude (deg)</
RequiredFieldValidator
>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"HaulLonm"
HeaderText
=
"Haul Longitude (min)"
UniqueName
=
"HaulLonm"
Visible
=
"false"
>
<
ColumnValidationSettings
EnableRequiredFieldValidation
=
"True"
>
<
RequiredFieldValidator
ID
=
"RFHaulLongitudeM"
Font-Bold
=
"True"
> Enter Haul Longitude (min)</
RequiredFieldValidator
>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
UniqueName
=
"HaulEastWest"
ColumnEditorID
=
"HaulEastWest"
HeaderText
=
"Haul East/West"
Visible
=
"false"
>
<
ItemTemplate
>
<%# Eval("HaulEW")%>
</
ItemTemplate
>
<
EditItemTemplate
>
<
asp:RadioButtonList
ID
=
"rdHaulEastWest"
runat
=
"server"
RepeatDirection
=
"Horizontal"
>
<
asp:ListItem
Text
=
"East"
Value
=
"2"
></
asp:ListItem
>
<
asp:ListItem
Text
=
"West"
Value
=
"1"
></
asp:ListItem
>
</
asp:RadioButtonList
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridDropDownColumn
DataField
=
"TowRegion"
HeaderText
=
"Tow Region"
ListTextField
=
"Name"
ListValueField
=
"Name"
UniqueName
=
"TowRegion"
ColumnEditorID
=
"TowRegion"
Visible
=
"false"
DropDownControlType
=
"DropDownList"
></
telerik:GridDropDownColumn
>
<
telerik:GridDropDownColumn
DataField
=
"HaulRectangle"
HeaderText
=
"Haul Rectangle"
ListTextField
=
"Code"
ListValueField
=
"Code"
UniqueName
=
"HaulRectangle"
ColumnEditorID
=
"HaulRectangle"
Visible
=
"false"
DropDownControlType
=
"DropDownList"
></
telerik:GridDropDownColumn
>
<
telerik:GridDropDownColumn
DataField
=
"WindSpeedCode"
HeaderText
=
"Wind Speed"
ListTextField
=
"Name"
ListValueField
=
"Code"
UniqueName
=
"WindSpeed"
ColumnEditorID
=
"WindSpeed"
Visible
=
"false"
DropDownControlType
=
"DropDownList"
></
telerik:GridDropDownColumn
>
<
telerik:GridDropDownColumn
DataField
=
"WindDirectionCode"
HeaderText
=
"Wind Direction"
ListTextField
=
"Name"
ListValueField
=
"Code"
UniqueName
=
"WindDirection"
ColumnEditorID
=
"WindDirection"
Visible
=
"false"
DropDownControlType
=
"DropDownList"
></
telerik:GridDropDownColumn
>
<
telerik:GridDropDownColumn
DataField
=
"SeaStateCode"
HeaderText
=
"Sea State"
ListTextField
=
"Name"
ListValueField
=
"Code"
UniqueName
=
"SeaState"
ColumnEditorID
=
"SeaState"
Visible
=
"false"
DropDownControlType
=
"DropDownList"
></
telerik:GridDropDownColumn
>
<
telerik:GridDropDownColumn
DataField
=
"SelectivityDeviceCode"
HeaderText
=
"Selectivity Device"
ListTextField
=
"nvcSelectivityDeviceName"
ListValueField
=
"intSelectivityDeviceID"
UniqueName
=
"SelectivityDevice"
Visible
=
"false"
DropDownControlType
=
"DropDownList"
></
telerik:GridDropDownColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
And the table that contains the comboboxes is as follows:
<
table
class
=
"tbldialog"
id
=
"Table1"
cellspacing
=
"1"
cellpadding
=
"1"
width
=
"500"
border
=
"0"
>
<
tr
>
<
td
><
asp:label
id
=
"lblId"
runat
=
"server"
CssClass
=
"label"
>Observer Name</
asp:label
></
td
>
<
td
>
<
asp:DropDownList
ID
=
"ddlID"
runat
=
"server"
DataSourceID
=
"ODS_Observers"
DataTextField
=
"ObserverName"
DataValueField
=
"ObserverInitials"
CssClass
=
"inputLong"
AutoPostBack
=
"True"
></
asp:DropDownList
>
<
asp:ObjectDataSource
ID
=
"ODS_Observers"
runat
=
"server"
OldValuesParameterFormatString
=
"original_{0}"
SelectMethod
=
"GetData"
TypeName
=
"DS_DiscardsTableAdapters.USP_ObserversSelectTableAdapter"
></
asp:ObjectDataSource
>
</
td
>
</
tr
>
<
tr
>
<
td
><
asp:Label
ID
=
"lblYear"
runat
=
"server"
CssClass
=
"label"
>Year:</
asp:Label
></
td
>
<
td
>
<
asp:DropDownList
ID
=
"ddlYear"
runat
=
"server"
AutoPostBack
=
"True"
CssClass
=
"inputLong"
DataSourceID
=
"objTripCodeYears"
DataTextField
=
"TripYears"
DataValueField
=
"TripYears"
></
asp:DropDownList
>
<
asp:ObjectDataSource
ID
=
"objTripCodeYears"
runat
=
"server"
OldValuesParameterFormatString
=
"original_{0}"
SelectMethod
=
"GetDataTripCodeYears"
TypeName
=
"TripCodeYearsTableAdapters.SelectYearsFromTripCodesByIDTableAdapter"
>
<
SelectParameters
>
<
asp:ControlParameter
ControlID
=
"ddlID"
Name
=
"ObserverID"
PropertyName
=
"SelectedValue"
Type
=
"String"
/>
</
SelectParameters
>
</
asp:ObjectDataSource
>
</
td
>
</
tr
>
<
tr
>
<
td
><
asp:label
id
=
"lblTripCode"
runat
=
"server"
CssClass
=
"label"
>Trip Code:</
asp:label
></
td
>
<
td
>
<
asp:Label
ID
=
"lblTripCount"
runat
=
"server"
CssClass
=
"labelNoCount"
Visible
=
"false"
></
asp:Label
>
<
asp:DropDownList
ID
=
"ddlTripCode"
runat
=
"server"
AutoPostBack
=
"True"
CssClass
=
"inputLong"
DataSourceID
=
"objTripCodes"
DataTextField
=
"TripCode"
DataValueField
=
"TripCode"
></
asp:DropDownList
>
<
asp:ObjectDataSource
ID
=
"objTripCodes"
runat
=
"server"
OldValuesParameterFormatString
=
"original_{0}"
SelectMethod
=
"GetDisTripCodesByIDAndYear"
TypeName
=
"TripCodeYearsTableAdapters.DisGetTripCodesByIDAndYearTableAdapter"
>
<
SelectParameters
>
<
asp:ControlParameter
ControlID
=
"ddlID"
Name
=
"ObserverID"
PropertyName
=
"SelectedValue"
Type
=
"String"
/>
<
asp:ControlParameter
ControlID
=
"ddlYear"
Name
=
"TripYear"
PropertyName
=
"SelectedValue"
Type
=
"Int32"
/>
</
SelectParameters
>
</
asp:ObjectDataSource
>
</
td
>
</
tr
>
</
table
>
Whenever the ddlTripCode SelectedValue is changed, the grid needs rebound. The problem is that when ddlTripCode SelectedValue changes, the NeedDataSource appears to be retaining the PREVIOUS SelectedValue, not the new one.
Here is my NeedDataSource code:
Protected
Sub
RDHauls_NeedDataSource(
ByVal
source
As
Object
,
ByVal
e
As
GridNeedDataSourceEventArgs)
Handles
RDHauls.NeedDataSource
' Get the Trip Code for binding the grid
TripCode = RTrim(
CStr
(ddlTripCode.SelectedValue))
' Get all the haul(s) details for the trip code selected
Dim
ds
As
New
DSHaulsTableAdapters.DisGetHaulDetailsByTripcodeTableAdapter
' Bind the grid to the haul(s) details
RDHauls.DataSource = ds.GetHaulDetailsByTripcode(TripCode)
End
Sub
Any advice please? I have to keep re-selecting a ddlTripCode SelectedValue to get the grid to bind to the correct data.
Thank you, Ida