Hi
I am going round in circles trying to beat this problem which I fairly sure is a result trying bind the value of the combos box item to a column which may contain null value. The error occurs as soon as the the grid's 'Edit' button is clicked with some database items/
The relevant grid declaration is like this
<
telerik:GridTemplateColumn
DataField
=
"Marshals"
HeaderText
=
"Marshal"
SortExpression
=
"Marshals"
UniqueName
=
"Marshals"
Visible
=
"False"
>
<
EditItemTemplate
>
<
telerik:RadComboBox
ID
=
"RadComboBox1"
Runat
=
"server"
AppendDataBoundItems
=
"True"
SelectedValue='<%# bind("Marshals") %>'
Width="225px">
</
telerik:RadComboBox
>
</
EditItemTemplate
>
<
ItemTemplate
>
<
asp:Label
ID
=
"MarshalsLabel"
runat
=
"server"
Text='<%# Eval("Marshals") %>'></
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
And the code behind builds a dataset and binds to the combo
Protected Sub RadGrid1_ItemCreated(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated
If TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode Then
Dim editform As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
Dim combo As RadComboBox = DirectCast(editform.FindControl("RadComboBox1"), RadComboBox)
Bind(combo)
Dim combo2 As RadComboBox = DirectCast(editform.FindControl("RadComboBox2"), RadComboBox)
Bind(combo2)
End If
End Sub
Private Sub Bind(combo As RadComboBox)
Dim strMemberID As String = ""
Dim sb As New StringBuilder
Dim Ds As New DataSet
Dim UserTable As New DataTable("UserTable")
UserTable.Columns.Add("Text", GetType(String))
UserTable.Columns.Add("Value", GetType(String))
UserTable.Rows.Add("Pick one", "0")
Dim rdr As SqlDataReader = ConstClass.getCurrentMembers()
If rdr.HasRows Then
While rdr.Read()
' build a row of the combo
' Text
If Not IsDBNull(rdr("FirstName")) Then
sb.Append(rdr("FirstName"))
Else
sb.Append("")
End If
sb.Append(" ")
If Not IsDBNull(rdr("LastName")) Then
sb.Append(rdr("LastName"))
Else
sb.Append("")
End If
sb.Append(" & ")
If Not IsDBNull(rdr("PartnerFirstName")) Then
sb.Append(rdr("PartnerFirstName"))
Else
sb.Append("")
End If
sb.Append(" ")
If Not IsDBNull(rdr("PartnerLastName")) Then
sb.Append(rdr("PartnerLastName"))
Else
sb.Append("")
End If
If Not IsDBNull("MemberID") Then
strMemberID = rdr("MemberID")
Else
strMemberID = "0"
End If
UserTable.Rows.Add(sb.ToString, strMemberID)
sb.Clear()
End While
UserTable.AcceptChanges()
Ds.Tables.Add(UserTable)
Ds.AcceptChanges()
rdr.Close()
LiteralTest.Text = sb.ToString
Else
UserTable.Rows.Add(sb.ToString, strMemberID)
UserTable.AcceptChanges()
Ds.Tables.Add(UserTable)
Ds.AcceptChanges()
rdr.Close()
End If
combo.DataTextField = "Text"
combo.DataValueField = "Value"
combo.DataSource = Ds
End Sub
This all works just fine until when you try to edit an item that has a Null value for 'Marshals' (which is an integer) in the record.
How do I escape? I have tried several of the solutions in this forum that seem as if they might be my case but to no avail so far.
BTW I am using Q2 2010 on this website.
Thanks
Clive