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

Problem in edit mode

6 Answers 144 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shawn Amina
Top achievements
Rank 1
Shawn Amina asked on 11 Aug 2008, 10:19 PM

Problem description:

The sample project contains a RadGrid (2 columns, 4 rows) that switches the  second column in the second and fourth rows in edit mode. The problem is that the first column does not display its value anymore (the value is "lost") while the second column is in edit mode. When I try to iterate through all the rows in Save_Command handler, I cannot get the value from these columns either.


Default.aspx

<%

@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%

@ Register TagPrefix="tlk" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>

<%

@ Register TagPrefix="ajax" Namespace="System.Web.UI" Assembly="System.Web.Extensions" %>

<!

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

html xmlns="http://www.w3.org/1999/xhtml">

<

head runat="server">

<title>Untitled Page</title>

</

head>

<

body>

<form id="form1" runat="server">

<ajax:ScriptManager ID="ScriptManager" runat="server">

</ajax:ScriptManager>

<tlk:RadGrid ID="RadGrid1" Width="100%" AllowMultiRowEdit="true"

OnNeedDataSource="RadGrid_NeedDataSource" runat="server"

OnItemCreated="RadGrid1_ItemCreated" >

<MasterTableView ShowHeadersWhenNoRecords="true" Width="100%" AutoGenerateColumns="false" EditMode="InPlace" >

<Columns>

<tlk:GridBoundColumn UniqueName="Name" HeaderText="Name" DataField="Name" />

<tlk:GridBoundColumn UniqueName="Amount" HeaderText="Amount" DataField="Amount" />

</Columns>

<EditItemStyle BackColor="transparent" />

</MasterTableView>

<ClientSettings>

<Resizing AllowColumnResize="true" AllowRowResize="true" />

<Scrolling AllowScroll="true" UseStaticHeaders="true" />

</ClientSettings>

<HeaderStyle Width="150px" />

</tlk:RadGrid>

<div style="text-align:right; margin-top:5px">

<asp:Button ID="SaveButton" Text="Save" runat="server" OnCommand="Save_Command" />

</div>

</form>

</

body>

</

html>

Default.aspx.cs

using

System;

using

System.Data;

using

System.Configuration;

using

System.Collections;

using

System.Web;

using

System.Web.Security;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.WebControls.WebParts;

using

System.Web.UI.HtmlControls;

using

Telerik.Web.UI;

public

partial class _Default : System.Web.UI.Page

{

protected void RadGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)

{

DataTable table = new DataTable();

table.Columns.Add(

new DataColumn("Name"));

table.Columns.Add(

new DataColumn("Amount"));

table.Rows.Add(

new object[] { "John", "11" });

table.Rows.Add(

new object[] { "David", "22" });

table.Rows.Add(

new object[] { "Elvis", "33" });

table.Rows.Add(

new object[] { "Oliver", "44" });

((

RadGrid)source).DataSource = table;

}

protected void Page_PreRender(object sender, EventArgs e)

{

RadGrid1.Items[1].Edit =

true;

RadGrid1.Items[3].Edit =

true;

RadGrid1.Rebind();

}

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)

{

if (e.Item is GridDataItem && e.Item.IsInEditMode)

{

foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)

{

if (column is GridBoundColumn)

{

if (string.Compare(column.UniqueName, "Amount", StringComparison.InvariantCultureIgnoreCase) == 0)

{

((

GridBoundColumn)column).ReadOnly = false;

TextBox textBox = null;

if (e.Item is GridDataItem)

{

textBox = ((

TextBox)((GridDataItem)e.Item)[column.UniqueName].Controls[0]);

textBox.Style[

"width"] = "100%";

textBox.Style[

"height"] = "100%";

textBox.Style[

"border"] = "1px";

textBox.Style[

"text-align"] = "right";

}

}

else

{

((

GridBoundColumn)column).ReadOnly = true;

}

}

}

}

}

protected void Save_Command(object source, EventArgs e)

{

string name = "";

foreach (GridDataItem item in RadGrid1.Items)

{

name = item[

"Name"].Text;

}

}

}


I also have a second question: I would like to have an extra row to show the rollup on the editable column. Is it possible to have this total being updated as the user modifies the editable fields ?

6 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 14 Aug 2008, 02:36 PM
Hello Shawn Amina,

I suggest that you add the readonly field to the DataKeyNames collection of the MasterTableView in order to access its value as desired.

Find more about retrieving primary key values in the following online resources:
http://www.telerik.com/help/aspnet-ajax/grdretrieveprimarykeyfieldvaluesforitems.html
http://www.telerik.com/help/aspnet-ajax/grdaccessingcellsandrows.html
http://www.telerik.com/help/aspnet-ajax/grdupdatinginplaceandeditforms.html

Let us know if you need further directions/help.

Regards,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Shawn Amina
Top achievements
Rank 1
answered on 15 Aug 2008, 03:51 PM
Hello Iana,

Adding the readonly field to the DataKeyNames does not address (and does not solve) the first issue which is the fact that the read only field value is not displayed at all while the other column is in edit mode. Getting the read only value should work the same for all rows regardless of the other column being in edit mode or not. As such, adding the readonly field to the DataKeyNames is merely a workaround not a solution (or the "correct" way of doing it).

There is also a question at the end of my post. Could you please try to answer that too ?

Best Regards
0
Iana Tsolova
Telerik team
answered on 19 Aug 2008, 08:27 AM
Hello Shawn Amina,

Excuse me for not answering your question from the bottom of the ticket.
There is no built-in functionality in RadGrid for achieving the desired result from this second question.

Regarding your first issue:
Please try removing the transparent back color from the EditItemStyle or change with another one and check if the ReadOnly fields are displayed when in edit mode.

Sincerely yours,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Acadia
Top achievements
Rank 1
Iron
answered on 21 Aug 2008, 07:02 PM
I am having the exact same problem.  This appears to be a design issue or limitation in the Rad grid when using in-line editing.  You cannot access both the edit-mode column values and the non-edit-mode column values simultaneously.  I've written a ton of code to try to do this and you just can't as far as I can tell.

If there is a way I would like to know what it is.
0
Kiara
Top achievements
Rank 1
answered on 22 Aug 2008, 02:17 PM
Acadia, I found these resouces which elaborate on how to access the non-editable ow values as well as the data from the column editors in RadGrid - check them out:

http://www.telerik.com/help/aspnet-ajax/grdeditforms.html
http://www.telerik.com/demos/aspnet/prometheus/Grid/Examples/Programming/AccessingCellsAndRows/DefaultCS.aspx
http://www.telerik.com/help/aspnet-ajax/grdaccessingcellsandrows.html

Kiara
0
Acadia
Top achievements
Rank 1
Iron
answered on 22 Aug 2008, 02:31 PM
Thanks Kiara, but I actually posted my solution in my other thread this morning (entitled Grid Combobox in Edit Mode) and I feel it is a simpler way to do this, especially since I don't want to use EditForm as the edit mode, I want to use In-Place.

Thanks
Tags
Grid
Asked by
Shawn Amina
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Shawn Amina
Top achievements
Rank 1
Acadia
Top achievements
Rank 1
Iron
Kiara
Top achievements
Rank 1
Share this question
or