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

[Solved] Editing problem with Grid

7 Answers 302 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sergey
Top achievements
Rank 1
Sergey asked on 12 May 2008, 10:34 AM
Hi. My English is not good, but I will try to explain

problem #1
I'm working with website. URL doesn't changes during nagivating (url is storing inside the session at server side as inner url; inner url changes using special postbacks). ViewState is disabled. Ajax is in use widely

I have a lookup (drop down list) with button 'Edit' near it. On pressing 'Edit' button system shows (using AJAX) Telerik Grid  with Lookup's values to edit. Grid is inside of UpdatePanel
Firstly I tryied to use edit column:

<telerik:GridEditCommandColumn UniqueName="EditCommandColumn"/>

System goes to Edit mode well - I getting required events at server side (OnEdit, OnItemCommand).

Problems occurs when I try to do actions while I'm in edit mode - press Update or Cancel buttons. System fires no Grid's events. Looks like databiding 'loosing' edit state data (without databind system will not show Grid at all)


problem #2
I tryied to move to edit mode manually

<

telerik:GridTemplateColumn UniqueName="EditColumn">
<ItemTemplate>
    <asp:LinkButton ID="lbEdit" CommandName="ComEdit" runat="server" Text="Edit" />
    <asp:LinkButton ID="lbUpdate" CommandName="ComUpdate" runat="server" Text="Update" Visible="false"/>
    <asp:LinkButton ID="lbCancel" CommandName="ComCancel" runat="server" Text="Cancel" Visible="false"/>
</ItemTemplate>
</
telerik:GridTemplateColumn>

At server side I'm handling visibilty of these link buttons as well as moving/exiting edit mode
Problem is in getting edited values. I trying to get updated values in 'OnItemCommand' event. 

Telerik.Web.UI.

GridDataItem dataItem = e.Item as Telerik.Web.UI.GridDataItem;

string s = dataItem["ID"].Text;

However all values are "&nbsp;". Without databinding no values at all

I checked Forms data, edited values are there
this.Page.Request.Form["ctl03$ctl03$ctl01$ctl00$ctl03$ctl1~0$rgEditGrid$ctl00$ctl04$ctl01"] - 'Name' column
this.Page.Request.Form["ctl03$ctl03$ctl01$ctl00$ctl03$ctl1~0$rgEditGrid$ctl00$ctl04$ctl02"] - 'Description' column
this.Page.Request.Form["ctl03_ctl03_ctl01_ctl00_ctl03_ctl1~0_rgEditGrid_ClientState"] - is empty

However Unique ID's are differs:
dataItem["Name"].UniqueID "ctl03$ctl03$ctl01$ctl00$ctl03$ctl1~0$rgEditGrid$ctl00$ctl04$ctl04" string
dataItem["Description"].UniqueID "ctl03$ctl03$ctl01$ctl00$ctl03$ctl1~0$rgEditGrid$ctl00$ctl04$ctl05" string
dataItem["ID"].UniqueID "ctl03$ctl03$ctl01$ctl00$ctl03$ctl1~0$rgEditGrid$ctl00$ctl04$ctl03" string


So I have only 2 ways for now (I will try to do them in nearest time).
1) Create EditTemplate for Name and Description, with named controls. And try to search them directrly for values (I not sure they are exists there...)
2) Manually get data from Page.Request.Form data... Yes, thats not good

Do you have some comments/recomedations about these problems?
Telerik Grid is extremely powerful control, but it still unripe is some 'special' situations

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 12 May 2008, 11:42 AM
Hi,

Try setting the Event Handler for UpdateCommand and see whether it is firing on clicking the Update button?

ASPX:
<telerik:RadGrid ID="RadGrid1"    runat="server"  DataSourceID="SqlDataSource1" OnUpdateCommand="RadGrid1_UpdateCommand" OnItemCommand="RadGrid1_ItemCommand"  > 

CS:
protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e) 
    { 
       //...
    } 


Shinu.
0
Sergey
Top achievements
Rank 1
answered on 12 May 2008, 11:58 AM
Hi Shinu

Yes, I did everything as you said
Current declaration is here:

<

telerik:RadGrid ID="rgEditGrid" AllowPaging="False" runat="server" Skin="WebBlue" GridLines="None" AutoGenerateColumns="False" OnItemDataBound="rgEditGrid_ItemDataBound" OnItemCommand="rgEditGrid_ItemCommand" >
...
I tryied to catch OnUpdateCommand, OnItemUpdated  other similiar events (OnCancel, etc), but no success.

This applies to problem #1, when using <telerik:GridEditCommandColumn>

0
Sergey
Top achievements
Rank 1
answered on 12 May 2008, 12:37 PM
Ok, first way seems to be worked

I used Template field to show data, and searching for it at events

Field in Grid:

<

telerik:GridTemplateColumn DataField="Name" HeaderText="Name" UniqueName="Name">

    <
ItemTemplate><%# DataBinder.Eval(Container.DataItem, "Name") %> </ItemTemplate>

    <
EditItemTemplate><asp:TextBox ID="tbName" runat="server" Text=<%# DataBinder.Eval(Container.DataItem, "Name") %>></asp:TextBox> </EditItemTemplate>

</
telerik:GridTemplateColumn>

And searching value in code at ItemCommand event

Telerik.Web.UI.

GridDataItem dataItem = e.Item as Telerik.Web.UI.GridDataItem;
TextBox tbName = dataItem["Name"].FindControl("tbName") as TextBox;


Founded textbox contains edited value. Thanks God :)


However I still have a questions - why standart EditColumnt did not worked for me, and I had to write manually buttons handling (GridEditCommandColumn - problem 1), and why I can't get edited values (GridBoundColumn) - problem 2
0
Princy
Top achievements
Rank 2
answered on 13 May 2008, 07:54 AM
Hi Sergey,

Try binding the Grid in the NeedDataSource event. Go through the following online demo to get details about AdvanceDataBinding techniques.
Advanced data-binding

Princy.
0
Sergey
Top achievements
Rank 1
answered on 14 May 2008, 08:51 AM
Hi Princy

NeedDataSource event is not firing (!) in this case (Grid is invisible, and makes visible using AJAX after user press button)
It fires only if Grid is visible from start

thats because I have problems with Grid - it works badly in 'unusual behaviour'
0
Princy
Top achievements
Rank 2
answered on 14 May 2008, 09:48 AM
Hi,

Have you set the EventHandler for the NeedDataSource event in the aspx?

ASPX:
  <telerik:RadGrid ID="RadGrid1"    OnNeedDataSource="RadGrid1_NeedDataSource" > 


CS:
  protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)  
    {  
 
    } 

Thanks
Princy.
0
Sergey
Top achievements
Rank 1
answered on 14 May 2008, 10:29 AM
Hi

Yes, exactly as you said
Tags
Grid
Asked by
Sergey
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Sergey
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or