This is a migrated thread and some comments may be shown as answers.

Can't refresh the Radgrid after update

1 Answer 204 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Parodist
Top achievements
Rank 1
Parodist asked on 20 Jan 2009, 10:47 AM
Hi,

I have managed to update  the records in the database using the following codes however after the click event of the update button regardless of what it does ,simply doesn't get refresh.Radgrid gets refreshed with the updated data  if I click on end editing which is not what I want.
And whilst i try to insert records , it simply doesn't take,instead it scares me with an error message .i will very thankful to you if u can help me out.I use a liecensed version but can't open a ticket yet .

--------------Insert--------------

protected

void RadGrid1_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)

 

{

 

 

GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item;

 

ErrorMsg - "Unable to cast object of type 'Telerik.Web.UI.GridCommandItem' to type 'Telerik.Web.UI.GridEditFormInsertItem'."



string
Activity = (insertedItem["Activity"].Controls[0] as TextBox).Text;

 

 

string Status = (insertedItem["Status"].Controls[0] as TextBox).Text;

 

 

string Comments = (insertedItem["Comments"].Controls[0] as TextBox).Text;

 

 

 

try

 

{

 

string Query = null;

 

 

Query =

"INSERT into SheduleActivityDetails(Activity,Status,Comments) values('" + Activity + "','" + Status + "','" + Comments + "')";

 

objDataLayer.ExecuteNonQuery(Query);

 

}

 

catch (Exception ex)

 

{

RadGrid1.Controls.Add(

new LiteralControl("Unable to insert Activity. Reason: " + ex.Message));

 

e.Canceled =

true;

 

}

 


------ data source

 

protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)

 

{

 

 

string Query = "";

 

 

DataTable dt = null;

 

Query =

"select D.Id,Activity,Status,Comments from ScheduleActivitymaster M join ScheduleActivitydetails D on M.ActivityID = D.ActivityID where M.ActivityID='" + RadComboBox1.SelectedValue + "'";

 

dt = objDataLayer.GetDataTable(Query);

RadGrid1.DataSource = dt;

//Can't use Radgrid1.rebind();

 

}


------Update -----


 

protected void RadGrid1_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)

 

{

 

GridEditableItem editedItem = e.Item as GridEditableItem;

 

 

string Id = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["Id"].ToString();

 

 

string Activity = (editedItem["Activity"].Controls[0] as TextBox).Text;

 

 

string Status = (editedItem["Status"].Controls[0] as TextBox).Text;

 

 

string Comments= (editedItem["Comments"].Controls[0] as TextBox).Text;

 

 

 

try

 

{

 

string Query = null;

 

Query =

"UPDATE ScheduleActivityDetails set Activity='" + Activity + "',Status='" + Status + "',Comments='" + Comments + "' where Id='" + Id + "'";

 

objDataLayer.ExecuteNonQuery(Query);
//tried assigning -1 to radgridItemIdex but no joy

Radgrid.rebind();

 

}

 

 

catch (Exception ex)

 

{

RadGrid1.Controls.Add(

new LiteralControl("Unable to update Activity. Reason: " + ex.Message));

 

e.Canceled =

true;

 

}

}

 



------Rad grid --------

<

telerik:RadGrid ID="RadGrid1" runat="server"

 

 

Width="600px" AllowMultiRowSelection="false" AllowMultiRowEdit="false" AllowAutomaticInserts="false"

 

 

AllowAutomaticUpdates="true" AllowPaging="true" ShowStatusBar="true" AutoGenerateEditColumn="false"

 

 

EnableAJAX="true" OnNeedDataSource="RadGrid1_NeedDataSource"

 

 

OnInsertCommand="RadGrid1_InsertCommand" OnUpdateCommand="RadGrid1_UpdateCommand"

 

 

ShowFooter="True" OnItemCreated="RadGrid1_ItemCreated" Skin="Office2007">

 

 

 

 

 

<ClientSettings>

 

 

<Selecting AllowRowSelect="true" EnableDragToSelectRows="true" />

 

 

</ClientSettings>

 

 

 

<MasterTableView CommandItemDisplay="Top" DataKeyNames="Id" EditMode="InPlace" AllowAutomaticInserts="False" AutoGenerateColumns="false" Width="100%">

 

 

 

<Columns>

 

 

<telerik:GridClientSelectColumn HeaderStyle-Width="40px" />

 

 

 

 

<telerik:GridBoundColumn DataField="Id" Visible="true" HeaderText="Id"

 

 

UniqueName="Id" ReadOnly="True">

 

 

</telerik:GridBoundColumn>

 

 

 

 

 

<telerik:GridBoundColumn DataField="Activity" HeaderText="Activity" SortExpression="Activity"

 

 

UniqueName="Activity">

 

 

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Status" HeaderText="Status" SortExpression="Status"

 

 

UniqueName="Status" Visible="true" EditFormColumnIndex="1">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Comments" HeaderText="Comments" SortExpression="Comments"

 

 

UniqueName="Comments" Visible="true" EditFormColumnIndex="1">

 

 

</telerik:GridBoundColumn>

 

 

 

 

</Columns>

 

 

 

<CommandItemTemplate>

 

 

 

<div style="padding: 10px 0px;">

 

 

 

 

<asp:LinkButton Style="vertical-align: bottom" ID="btnEditSelected" runat="server"

 

 

CommandName="EditSelected" CausesValidation="false" Visible='<%# RadGrid1.EditIndexes.Count == 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="=../../Images/Edit.gif" /> Edit Selected Activity</asp:LinkButton>

 

 

 

<asp:LinkButton ID="LinkButton1" runat="server" CommandName="UpdateEdited" Visible='<%# RadGrid1.EditIndexes.Count > 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="=../../Images/Update.gif" /> Update Activity</asp:LinkButton>

 

 

&nbsp;

 

 

 

 

 

<asp:LinkButton ID="LinkButton2" runat="server" CommandName="CancelAll" CausesValidation="false"

 

 

Visible='<%# RadGrid1.EditIndexes.Count > 0 || RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="=../../Images/edit.png" /> Cancel editing</asp:LinkButton>

 

 

&nbsp;

 

 

 

 

<asp:LinkButton ID="LinkButton3" runat="server" CommandName="InitInsert" Visible='<%# !RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="=../../Images/AddRecord.gif" /> Add new Activity</asp:LinkButton>

 

 

 

<asp:LinkButton ID="LinkButton4" runat="server" CommandName="PerformInsert" Visible='<%# RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="=../../Images/Insert.gif" /> Add this Activity</asp:LinkButton>

 

 

&nbsp; &nbsp;&nbsp;&nbsp;

 

 

 

<asp:LinkButton ID="LinkButton5" runat="server" CommandName="RebindGrid"><img style="border:0px;vertical-align:middle;" alt="" src="=../../Images/Refresh.gif"/> Refresh Activities</asp:LinkButton>

 

 

</div>

 

 

 

</CommandItemTemplate>

 

 

 

 

 

 

<EditFormSettings ColumnNumber="2" CaptionFormatString="Edit properties of Activity with Id {0}"

 

 

CaptionDataField="ActivityId">

 

 

 

 

 

 

<FormTableItemStyle Wrap="False"></FormTableItemStyle>

 

 

<FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>

 

 

<FormMainTableStyle GridLines="Horizontal" CellSpacing="0" CellPadding="5" BackColor="White"

 

 

Width="100%"/>

 

 

<FormTableStyle CellSpacing="0" CellPadding="2" CssClass="module" Height="110px"

 

 

BackColor="White"/>

 

 

<FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>

 

 

<EditColumn ButtonType="ImageButton" InsertText="Insert Order" UpdateText="Update record"

 

 

UniqueName="EditCommandColumn1" CancelText="Cancel edit">

 

 

</EditColumn>

 

 

<FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>

 

 

</EditFormSettings>

 

 

 

 

 

</MasterTableView>

 

 

 

 

 

</telerik:RadGrid>

 



 

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 21 Jan 2009, 12:34 PM
Hi Parodist,

Can you please remove the AllowAutomaticUpdates="true", and let me know how it goes.  If you are handling the inserts/updates manually, the automatic operations for the control should be disabled.

Greetings,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Parodist
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or