BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
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
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("", "\r");
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 + "";
});
}
}
//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