I have a Grid with a Binary Image and a Description field. Inserts work great, both binary image and description are saved correctly.
On updates, though, the description field is not getting updated, the "old" value is passed to the SqlDataSource, not the new edited value from the grid.
In other words... I add a record, with an image and a description (say, 'testing'). Verified it is saved in the database correctly (query in SQL Management Studio).
I then edit the record and change the description to 'Testing1234', tab off description field, click save, the new value is not saved, the old value 'testing' is.
I added some code to the SQL Datasources' OnInserting and OnUpdating events (see code below.)
On insert, the value of the @Description parameter is 'Testing' (when Testing is typed in the description.)
On update, changing the value in the Grid to 'Testing1234' and clicking the save button yields 'Testing' for the value of the @Description parameter in the OnUpdating event, not the new 'Testing1234' value entered in the Grid.
Any thoughts on why this is happening would be helpful. I've been staring at it now for 6 hours w/ no success, and other, similar Grids work fine (although this is my only grid which uses an Binary Image.)
My code:
<
asp:SqlDataSource
ID
=
"SqlDataSource_Receipts"
runat
=
"server"
ConflictDetection
=
"CompareAllValues"
OnInserting
=
"SqlDataSource_Receipts_Inserting"
OnUpdating
=
"SqlDataSource_Receipts_Updating"
ConnectionString="<%$ ConnectionStrings:Receipts %>"
DeleteCommand="DELETE FROM Receipts WHERE Receipt_GUID = @Receipt_GUID"
InsertCommand="INSERT INTO Receipts (Receipt_GUID, Employee_GUID, Description, ReceiptImage) VALUES (NEWID(), @Employee_GUID, @Description, @ReceiptImage)"
SelectCommand="SELECT * FROM Receipts WHERE Employee_GUID = @Employee_GUID"
UpdateCommand="UPDATE Receipts SET Description = @Description, ReceiptImage = CASE WHEN ISNULL(DATALENGTH(CONVERT(varbinary(MAX), @ReceiptImage)), -1) = -1 THEN ReceiptImage ELSE CONVERT(VARBINARY(MAX), @ReceiptImage) END WHERE Receipt_GUID = @Receipt_GUID">
<
DeleteParameters
>
<
asp:Parameter
Name
=
"Receipt_GUID"
/>
</
DeleteParameters
>
<
InsertParameters
>
<
asp:ControlParameter
ControlID
=
"RadGrid_Employees"
Name
=
"Employee_GUID"
PropertyName
=
"SelectedValues['Employee_GUID']"
DbType
=
"Guid"
/>
<
asp:Parameter
Name
=
"Description"
/>
<
asp:Parameter
Name
=
"ReceiptImage"
/>
</
InsertParameters
>
<
SelectParameters
>
<
asp:ControlParameter
ControlID
=
"RadGrid_Employees"
Name
=
"Employee_GUID"
PropertyName
=
"SelectedValues['Employee_GUID']"
DbType
=
"Guid"
/>
</
SelectParameters
>
<
UpdateParameters
>
<
asp:Parameter
Name
=
"Receipt_GUID"
/>
<
asp:Parameter
Name
=
"Description"
/>
<
asp:Parameter
Name
=
"ReceiptImage"
/>
</
UpdateParameters
>
</
asp:SqlDataSource
>
The radgrid definition:
<
telerik:RadGrid
ID
=
"RadGrid_Receipts"
runat
=
"server"
AutoGenerateColumns
=
"False"
DataSourceID
=
"SqlDataSource_Receipts"
GridLines
=
"None"
Width
=
"100%"
AllowAutomaticUpdates
=
"True"
AllowAutomaticInserts
=
"True"
AllowAutomaticDeletes
=
"True"
AllowSorting
=
"True"
OnItemDataBound
=
"RadGrid_Receipts_ItemDataBound"
CellSpacing
=
"0"
ShowStatusBar
=
"True"
ShowFooter
=
"true"
AutoGenerateDeleteColumn
=
"False"
AutoGenerateEditColumn
=
"False"
>
<
MasterTableView
CommandItemDisplay
=
"Bottom"
AllowPaging
=
"True"
EditMode
=
"InPlace"
DataKeyNames
=
"Receipt_GUID, Employee_GUID"
>
<
Columns
>
<
telerik:GridEditCommandColumn
ButtonType
=
"ImageButton"
UniqueName
=
"EditCommandColumn"
>
<
HeaderStyle
Width
=
"50px"
/>
<
ItemStyle
CssClass
=
"MyImageButton"
Width
=
"50px"
/>
</
telerik:GridEditCommandColumn
>
<
telerik:GridButtonColumn
ButtonType
=
"ImageButton"
CommandName
=
"Delete"
ConfirmDialogType
=
"RadWindow"
ConfirmText
=
"Delete this Receipt?"
ConfirmTitle
=
"Delete"
Text
=
"Delete"
UniqueName
=
"DeleteColumn"
>
<
HeaderStyle
Width
=
"25px"
/>
<
ItemStyle
CssClass
=
"MyImageButton"
HorizontalAlign
=
"Center"
Width
=
"25px"
/>
</
telerik:GridButtonColumn
>
<
telerik:GridBinaryImageColumn
DataField
=
"ReceiptThumb"
HeaderText
=
"Receipt Image"
UniqueName
=
"ReceiptThumb"
ResizeMode
=
"Fit"
ImageWidth
=
"100"
ImageHeight
=
"100"
/>
<
telerik:GridBoundColumn
DataField
=
"Description"
HeaderText
=
"Description"
SortExpression
=
"Description"
UniqueName
=
"Description"
ItemStyle-Width
=
"500px"
HeaderStyle-HorizontalAlign
=
"Center"
/>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
My Datasource onInserting/Updating events:
protected void SqlDataSource_Receipts_Inserting(object sender, SqlDataSourceCommandEventArgs e)
{
SqlParameter d = (SqlParameter)e.Command.Parameters["@Description"];
// d.Value = 'Testing' , correct, this is what I enter on the form.
}
protected void SqlDataSource_Receipts_Updating(object sender, SqlDataSourceCommandEventArgs e)
{
SqlParameter d = (SqlParameter)e.Command.Parameters["@Description"];
// d.Value = 'Testing' despite having typed 'Testing1234' in the RadGrid before clicking Save
}