
Philippe GRACA
Top achievements
Rank 1
Philippe GRACA
asked on 16 Jun 2008, 09:14 AM
Hi folks
I'm trying to implement the following scenario:
I've one grid with two columns (basically LABEL/VALUE). When the user is double clicking on the row, I want the Value column to become editable with either a simple text box, a date time picker, a complete user control,... depending on the VALUE column data type.
I do not want to use an user control that will display under the edited row.
Any ideas?
Thx a lot
Philippe
I'm trying to implement the following scenario:
I've one grid with two columns (basically LABEL/VALUE). When the user is double clicking on the row, I want the Value column to become editable with either a simple text box, a date time picker, a complete user control,... depending on the VALUE column data type.
I do not want to use an user control that will display under the edited row.
Any ideas?
Thx a lot
Philippe
7 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 16 Jun 2008, 09:45 AM
0

Philippe GRACA
Top achievements
Rank 1
answered on 16 Jun 2008, 12:33 PM
Hi
My issue is not on "how to edit on double click", it is related to "How can I show a different editor depending on the cell data type.
Let's say that my query to retrieve data is LABEL, VALUE, DATATYPE
The datatype column will be hidden to the user.
When the edit mode is fired, I want to show a different editor in the VALUE column depending on the DATATYPE value.
Am I clear???
Thx a lot
Philippe
My issue is not on "how to edit on double click", it is related to "How can I show a different editor depending on the cell data type.
Let's say that my query to retrieve data is LABEL, VALUE, DATATYPE
The datatype column will be hidden to the user.
When the edit mode is fired, I want to show a different editor in the VALUE column depending on the DATATYPE value.
Am I clear???
Thx a lot
Philippe
0

Philippe GRACA
Top achievements
Rank 1
answered on 17 Jun 2008, 07:43 AM
Hi
Since nobody is answering, must I assume that this is not feasible?
Best regards
Philippe
Since nobody is answering, must I assume that this is not feasible?
Best regards
Philippe
0

Princy
Top achievements
Rank 2
answered on 17 Jun 2008, 07:43 AM
Hi Philippe,
Try the following code snippet to achieve the desired scenario.
ASPX:
CS:
Thanks
Princy.
Try the following code snippet to achieve the desired scenario.
ASPX:
<MasterTableView DataKeyNames="DataType" > |
CS:
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode)) |
{ |
RadDatePicker datpkr = new RadDatePicker(); |
datpkr.ID = "RadDatePicker12"; |
RadNumericTextBox numtxtbx = new RadNumericTextBox(); |
numtxtbx.ID = "RadNumericTextBox12"; |
RadTextBox txtbx = new RadTextBox(); |
txtbx.ID = "RadTextBox12"; |
GridEditableItem editeditem = (GridEditableItem)e.Item; |
editeditem["ValueCol"].Controls.Clear(); |
//Access DataKeyValue here |
string strDataType = editeditem.GetDataKeyValue("DataType").ToString(); |
if (strDataType == "DateTime") |
{ |
editeditem["ValueCol"].Controls.Add(datpkr); |
} |
else if (strDataType == "int") |
{ |
editeditem["ValueCol"].Controls.Add(numtxtbx); |
} |
else |
{ |
editeditem["ValueCol"].Controls.Add(txtbx); |
} |
} |
} |
Thanks
Princy.
0

Philippe GRACA
Top achievements
Rank 1
answered on 17 Jun 2008, 09:01 AM
Hi and thx a lot for the proposal
It sounds great but unfortunaly, I'm having a "Editor cannot be initialized for column" exception. How can I tell my cell that it should use the newly added control during the databound event?
Regards
Philippe
It sounds great but unfortunaly, I'm having a "Editor cannot be initialized for column" exception. How can I tell my cell that it should use the newly added control during the databound event?
Regards
Philippe
0

Shinu
Top achievements
Rank 2
answered on 17 Jun 2008, 09:11 AM
Hi,
Go through the following forum link which discuss a similar error.
Datepicker control as Column problem
Shinu.
Go through the following forum link which discuss a similar error.
Datepicker control as Column problem
Shinu.
0

Philippe GRACA
Top achievements
Rank 1
answered on 03 Jul 2008, 03:37 PM
Hi
I finally made it :)
And the code behind
Hope this will help someone. I'm now opening a new post for another related issue :)
I finally made it :)
<telerik:GridTemplateColumn UniqueName="Value" HeaderText="Value" DataField="Value"> |
<HeaderStyle Width="400px"></HeaderStyle> |
<ItemTemplate> |
<asp:Label ID="v" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Value")%>' |
CssClass="ed" /> |
</ItemTemplate> |
<EditItemTemplate> |
<telerik:RadTextBox ID="rtb" runat="server" TextMode="SingleLine" Rows="2"> |
</telerik:RadTextBox> |
<telerik:RadNumericTextBox ID="rntb" runat="server"> |
</telerik:RadNumericTextBox> |
<telerik:RadEditor ID="re" runat="server" EditModes="Design, Html" ToolsFile="~/App_Data/ToolsFile.xml" |
Skin="Vista" ConvertTagsToLower="True" ConvertToXhtml="True" EnableClientSerialize="False" |
EnableResize="false" EnableContextMenus="True" EnableDocking="False" EnableEnhancedEdit="True" |
EnableHtmlIndentation="True" EnableServerSideRendering="True" PassSessionData="True" |
EnableTab="false" RenderAsTextArea="False" SpellEditDistance="1" Width="100%" ToolbarMode="Default" |
ToolsWidth="" EnableViewState="False" SaveAsXhtml="True" ShowSubmitCancelButtons="False" |
StripFormattingOnPaste="MSWordNoFonts" ShowPreviewMode="False" Height="200px" OnClientLoad="OnClientLoad"> |
</telerik:RadEditor> |
<telerik:RadDatePicker ID="rdtp" AllowEmpty="true" Style="vertical-align: middle;" |
MinDate="2006-2-1" runat="server" Skin="Vista"> |
</telerik:RadDatePicker> |
</EditItemTemplate> |
</telerik:GridTemplateColumn> |
And the code behind
protected void tg_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
try |
{ |
if (e.Item is GridEditableItem && e.Item.IsInEditMode) |
{ |
GridEditableItem edititem = (GridEditableItem)e.Item; |
TableCell cell = edititem["Value"]; |
int dataType = Convert.ToInt32(edititem.GetDataKeyValue("EntryTypeId")); |
object v = ((DataRowView)edititem.DataItem)["Value"]; |
Control rtb = cell.FindControl("rtb"); |
Control re = cell.FindControl("re"); |
Control rntb = cell.FindControl("rntb"); |
Control rdtp = cell.FindControl("rdtp"); |
switch (dataType) //0=Text, 1=Rich Text, 2=Image, 3=Date |
{ |
case 0: |
if (re != null) cell.Controls.Remove(re); |
if (rntb != null) cell.Controls.Remove(rntb); |
if (rdtp != null) cell.Controls.Remove(rdtp); |
((RadTextBox)rtb).Text = v.ToString(); |
break; |
case 1: |
if (rtb != null) cell.Controls.Remove(rtb); |
if (rntb != null) cell.Controls.Remove(rntb); |
if (rdtp != null) cell.Controls.Remove(rdtp); |
((RadEditor)re).Content = v.ToString(); |
break; |
case 2: |
if (rtb != null) cell.Controls.Remove(rtb); |
if (re != null) cell.Controls.Remove(re); |
if (rdtp != null) cell.Controls.Remove(rdtp); |
((RadNumericTextBox)rntb).Text = v.ToString(); |
break; |
case 3: |
if (rtb != null) cell.Controls.Remove(rtb); |
if (re != null) cell.Controls.Remove(re); |
if (rntb != null) cell.Controls.Remove(rntb); |
((RadDatePicker)rdtp).DateInput.Attributes.Add("OnClick", "$find('" + rdtp.ClientID + "').showPopup();"); |
((RadDatePicker)rdtp).SelectedDate = Convert.ToDateTime(v); |
break; |
default: break; |
} |
} |
} |
catch (Exception ex) |
{ |
lbDebug.Text += "<br/>" + ex.ToString(); |
} |
} |
Hope this will help someone. I'm now opening a new post for another related issue :)