We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

GridGroupControl select single cell and copy the content

Thread ID:

Created:

Updated:

Platform:

Replies:

117228 Sep 10,2014 09:42 PM Sep 17,2014 05:23 AM ASP.NET Web Forms (Classic) 2
loading
Tags: GridGroupingControl
Siang
Asked On September 10, 2014 09:42 PM

Is there any way to select a single cell or column?
And copy the selected cell content?

Silambarasan I [Syncfusion]
Replied On September 15, 2014 11:48 PM

Hi Siang,

 

Thank you for using Syncfusion products.

 

We need to analyse on this and we will update you with further details on September 17, 2014.

 

Please let us know if you need any further assistance.

 

Regards,

Silambarasan I


Silambarasan I [Syncfusion]
Replied On September 17, 2014 05:23 AM

Hi Siang,

 

Thanks for your patience.

 

We are glad to let you know that your requirement (“To copy the selected content of the single cell or single columns cells in Ajax Grid”) can be achieved by using button click event or by using keydown (Ctrl+c) client-side event.  Please refer the below code snippets.

 

CODE SNIPPET:

 

[ASPX]

 

<div>

<Syncfusion:GridGroupingControl ID="GridGroupingControl1" runat="server" AjaxAutoformat="Office2007Blue"

EnableCallbacks="false" ShowGroupDropArea="false"  EnableAjaxMode="true"

DataSourceCachingMode="ViewState" AllowMultiSorting="false"  PageSize="15" PageIndexButtonCount="3" >

//...

</Syncfusion:GridGroupingControl>

</div>

<asp:HiddenField ID="forSelectedContent" runat="server"></asp:HiddenField><br />

<div><b>Note:</b> Click "Copy !" button or press Ctrl+c to copy selected cells in Grid. </div>

<asp:Button ID="Button1" Font-Size="Large" runat="server" Text="Copy !" OnClick="Button1_Click" OnClientClick="CopySelectedContent()" />

 

[ASPX.CS]

 

public partial class Default : System.Web.UI.Page

{

//...

 

private static string _Val;

public static string Val

{

get { return _Val; }

set { _Val = value; }

}

 

protected void Button1_Click(object sender, EventArgs e)

{

Val = this.forSelectedContent.Value;

this.startCopy();

}

 

protected void startCopy()

{

if (Val != "")

{

Thread staThread = new Thread(new ThreadStart(myMethod));

staThread.ApartmentState = ApartmentState.STA;

staThread.Start();

while (!staThread.IsAlive)

staThread.Abort();

}

}

 

[WebMethod]

public static void copyMethod(string val)

{

Val = val.Replace("\n", "\r\n");

new Default().startCopy();

}

 

public static void myMethod()

{

Clipboard.Clear();

Clipboard.SetText(Val);

}

}

 

[SCRIPT]

 

var isCtrl = false;

var isC = false;

 

//Copy selected content to hidden variable

function CopySelectedContent() {

var gridObj = $find("GridGroupingControl1");

 

var selectedCellValue = $("." + gridObj.get_SelectionManager().currentCellBackground).text();

 

if (selectedCellValue != "")

document.getElementById('forSelectedContent').value = selectedCellValue;

else {

var selectedColumnValues = $("." + gridObj.get_SelectionManager().get_SelectedColumnCss());

document.getElementById('forSelectedContent').value = "";

var tempString = "";

$.each(selectedColumnValues, function (index, val) {

document.getElementById('forSelectedContent').value += val.textContent + "\n";

});

}

}

 

//Copy by keydown event (Ctrl+c)

$(document).keydown(function (event) {

var keycode = (event.keyCode ? event.keyCode : event.which);

if (keycode == 17 || keycode == 67) {

isCtrl = (keycode == 17) ? true : (isC = true);

if (isCtrl && isC) {

CopySelectedContent();

PageMethods.copyMethod(document.getElementById('forSelectedContent').value);

isCtrl = isC = false;

}

}

else

isCtrl = isC = false;

});

 

For your convenience, we have prepared a simple sample to demonstrate this and the same can be downloaded from the below link.

 

Sample: SampleProject.zip

 

Please let us know if you need any further assistance.

 

Regards,

 

Silambarasan I


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;