HELP! (please)
I have a RadGrid. I have two updatable columns. When I try to update, nothing happens.
Here is my front end....
Here is my back end... (my data source is in a data access layer)
My update is a stored procedure that requires three Parameters... the ID of the edited row, the value of the edited column, or columns.
I can't get it to do the actual update. I've looked at samples, and tried to match the examples (with minor changes for my stored procedures - and population). However, I'm still not able to get the update working.
If you can pinpoint my error and help me correct it, I'd be very much obliged.
Thanks, in advance. :-)
I have a RadGrid. I have two updatable columns. When I try to update, nothing happens.
Here is my front end....
<
telerik:RadGrid
Width
=
"550px"
ID
=
"RadGrid1"
AllowMultiRowEdit
=
"True"
runat
=
"server"
OnItemCommand
=
"RadGrid1_ItemCommand"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
OnItemDataBound
=
"RadGrid1_ItemDataBound"
>
<
MasterTableView
DataKeyNames
=
"HandlingPriceEstimationID"
AutoGenerateColumns
=
"False"
EditMode
=
"InPlace"
CommandItemDisplay
=
"Bottom"
>
<
Columns
>
<
telerik:GridBoundColumn
ReadOnly
=
"true"
DataField
=
"HandlingPriceEstimationID"
UniqueName
=
"HandlingPriceEstimationID"
Visible
=
"False"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
ReadOnly
=
"true"
DataField
=
"UoMCode"
UniqueName
=
"UoMCode"
Visible
=
"False"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
ReadOnly
=
"true"
DataField
=
"UoMName"
UniqueName
=
"UoMName"
HeaderText
=
"UOM"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
ReadOnly
=
"true"
DataField
=
"DimCode"
UniqueName
=
"DimCode"
HeaderText
=
"IBU"
>
</
telerik:GridBoundColumn
>
<
telerik:GridNumericColumn
ReadOnly
=
"False"
DataField
=
"FirstItem"
UniqueName
=
"FirstItem"
HeaderText
=
"First Item"
/>
<
telerik:GridNumericColumn
ReadOnly
=
"False"
DataField
=
"RemainItem"
UniqueName
=
"RemainItem"
HeaderText
=
"Remaining Item"
/>
<
telerik:GridEditCommandColumn
UniqueName
=
"EditCommandColumn"
/>
</
Columns
>
<
CommandItemTemplate
>
<
asp:Button
runat
=
"server"
ID
=
"UpdateAll"
Text
=
"Update"
CommandName
=
"UpdateAll"
/>
</
CommandItemTemplate
>
</
MasterTableView
>
</
telerik:RadGrid
>
Here is my back end... (my data source is in a data access layer)
protected
void
RadGrid1_NeedDataSource(Object source, GridNeedDataSourceEventArgs e)
{
CP_PortalDb db =
new
CP_PortalDb();
DataTable dataTable =
new
DataTable();
dataTable = db.StoredProcedures.stp_HandlingPriceEstimationGETALL_Command();
string
prevHPEID =
""
;
foreach
(DataRow dRow
in
dataTable.Rows)
{
string
newHPEID = dataTable.Rows[0][
"HandlingPriceEstimationID"
].ToString();
if
(prevHPEID != newHPEID)
{
dRow[
"HandlingPriceEstimationID"
] = Convert.ToInt32(dataTable.Rows[0][
"HandlingPriceEstimationID"
]);
dRow[
"DimCode"
] = dataTable.Rows[0][
"DimCode"
].ToString();
dRow[
"UoMCode"
] = dataTable.Rows[0][
"UoMCode"
].ToString();
dRow[
"UoMName"
] = dataTable.Rows[0][
"UoMName"
].ToString();
dRow[
"FirstItem"
] = dataTable.Rows[0][
"FirstItem"
].ToString();
dRow[
"RemainItem"
] = dataTable.Rows[0][
"RemainItem"
].ToString();
}
prevHPEID = newHPEID;
}
RadGrid1.DataSource = dataTable;
}
protected
void
RadGrid1_ItemCommand(
object
source, GridCommandEventArgs e)
{
CP_PortalDb db =
new
CP_PortalDb();
if
(e.CommandName ==
"UpdateAll"
)
{
if
(RadGrid1.EditIndexes.Count == 0)
{
return
;
}
foreach
(GridDataItem editedItem
in
RadGrid1.EditItems)
{
Hashtable newValues =
new
Hashtable();
//The GridTableView will fill the values from all editable columns in the hash
e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem );
int
returnedID = Convert.ToInt32(editedItem.GetDataKeyValue(
"HandlingPriceEstimationID"
));
if
(e.Item
is
GridDataItem)
{
GridDataItem fItem = (GridDataItem) e.Item;
GridDataItem rItem = (GridDataItem) e.Item;
double
fItemHandPrice = Convert.ToDouble(fItem[
"FirstItem"
]);
double
rItemHandPrice = Convert.ToDouble(rItem[
"RemainingItem"
]);
db.StoredProcedures.stp_MaterialHandlingEstimationUPDATE_Command(returnedID, fItemHandPrice, rItemHandPrice);
}
editedItem.Edit =
false
;
}
e.Item.OwnerTableView.Rebind();
}
}
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem && e.Item.IsInEditMode)
{
GridDataItem dataItem = e.Item
as
GridDataItem;
//Hides the Update button for each edit form
dataItem[
"EditCommandColumn"
].Controls[0].Visible =
false
;
}
}
My update is a stored procedure that requires three Parameters... the ID of the edited row, the value of the edited column, or columns.
I can't get it to do the actual update. I've looked at samples, and tried to match the examples (with minor changes for my stored procedures - and population). However, I'm still not able to get the update working.
If you can pinpoint my error and help me correct it, I'd be very much obliged.
Thanks, in advance. :-)