upload multiple radgrids to single excel sheet with formatting options - c#

I want to upload 3radgrids to a single excel and that too in same sheet on a button click.
Like one table contents followed by other, and so on.
In between i need to add Headings other than the column headers for the contents,
Can anyone help me in this regard.
Protected void buttonclick(object o,sender s)
{
RadGrid1.ExportSettings.Excel.Format = (GridExcelExportFormat)Enum.Parse(typeof(GridExcelExportFormat), alternateText);
RadGrid1.ExportSettings.IgnorePaging = CheckBox1.Checked;
RadGrid1.ExportSettings.ExportOnlyData = true;
RadGrid1.ExportSettings.OpenInNewWindow = true;
RadGrid1.MasterTableView.ExportToExcel();
}

Add(your 3 grids) inside a dummy parent grid. Name the dummy radgrid as GridMain and export GridMain
Please look at the following code
<telerik:RadGrid ID="GridMain" runat="server" Skin="Default" ShowHeader="false" OnNeedDataSource="GridMain_NeedDataSource"
BorderStyle="None" Width="500px">
<MasterTableView>
<ItemTemplate>
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
Skin="Vista">
<MasterTableView AutoGenerateColumns="false">
<Columns>
<telerik:GridBoundColumn HeaderText="ID" UniqueName="ID" DataField="ID" />
</Columns>
</MasterTableView>
</telerik:RadGrid>
<telerik:RadGrid ID="RadGrid2" runat="server" OnNeedDataSource="RadGrid2_NeedDataSource"
Skin="Vista">
<MasterTableView AutoGenerateColumns="false">
<Columns>
<telerik:GridBoundColumn HeaderText="Description" UniqueName="Description" DataField="Description" />
</Columns>
</MasterTableView>
</telerik:RadGrid>
</ItemTemplate>
</MasterTableView>
</telerik:RadGrid>
There is forum post in telerik site, which talks about this issue.
Check it out Exporting Multiple Radgrids
Note: Simply leave blank in need data source

Related

Copy gridview cell value to the clipboard

I have a gridview with some values. If the user clicks on a link or button (here I took a Buttonfield with the text 'Copy') on one of the rows, it should copy a cell value of that row to the clipboard.
Is something like this possible in asp.net c# ?
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="id" DataSourceID="SqlDataSource1" Visible="False" OnRowDataBound="GridView1_RowDataBound"
onselectedindexchanged="GridView1_SelectedIndexChanged1">
<Columns>
<asp:BoundField DataField="Username" HeaderText="Username"
SortExpression="Username" />
<asp:BoundField DataField="Password" HeaderText="Password"
SortExpression="Password" />
<asp:CommandField ButtonType="Image" EditImageUrl="/images/edit.png" CancelImageUrl="/images/undo.png" UpdateImageUrl="/images/save.png" ShowEditButton="True" />
<asp:CommandField ButtonType="Image" ShowDeleteButton="True" DeleteImageUrl="/images/deletered.png" />
<asp:ButtonField Text="Copy" />
</Columns>
<EmptyDataTemplate>
No data available
</EmptyDataTemplate>
</asp:GridView>
There is no Onclick event available for a ButtonField. Otherwise I would think of using some javascript (I have seen that in other solutions)
Thanks for any input.
You can do that with windows form only, but since you are working on Web application you should write client side code which is javascript to copy data on client side not server side. checkout this link

Set custom NavigateUrl value from gridview c#

I have a gridview in which I want to load a users details. In this gridview I want to make the users phone number a hyperlink. This is so they can click on the link and it automatically rings the number using the phone software stored on the their pc. This works fine if you use the below syntax in html:
07123456789
My issue is that I want to do this in a gridview which populattes the phone number. The html has to have the 'tel:' bit in front of it first. I have tried everything please help! I want essentially above but to render in gridview with the loaded HomeNo where the phone number should be...HElp!
Gridview:
<asp:GridView ID="GridView1" runat="server" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="ds">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:HyperLinkField DataTextField="HomeNo" HeaderText="HomeNo" NavigateUrl="tel:" />
</Columns>
</asp:GridView>
<asp:GridView ID="GridView1" runat="server" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="ds">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# Eval("HomeNo", "tel:{0}") %>'
Text='<%# Eval("NomeNo") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
you would need to do this inside of an also if you have data it's reading from you need to do some code inside of the DataBound Event of the DataGrid
for example I have names and email addresses as a link in my current datagrid here is how I do it
<asp:TemplateColumn HeaderText="Scheduler" HeaderStyle-Font-Bold="true" HeaderStyle-Width="145">
<ItemTemplate>
<a href='<%#Eval("Email_Address") %>' ><%# Eval("Scheduler") %></a>
</ItemTemplate>
<HeaderStyle Font-Bold="True" />
</asp:TemplateColumn>
protected void dgShippers_DataBinding(object sender, EventArgs e)
{
foreach (DataRow r in dtShippers.Rows)
{
if (!System.Uri.IsWellFormedUriString(r.ItemArray[3].ToString(), UriKind.Absolute))
{
var tempHref = "<a href=mailto:" + r.ItemArray[4].ToString() + " />" + r.ItemArray[3].ToString()+ "</a>";
r.Table.Rows[0]["Scheduler"] = tempHref;
}
}
}

Selection of checkboxes lost during pagination of gridview

I have a problem in gridview, as per requirement i have set No of Records per page = 4 in gridview. I have to select Checkbox against every complaint but problem is then when i got to next pge in gridview and e.g fro 1 to 2 then when i come back to page 1 then it doesn't show TICK in check boxes . It doesn't remember my selection when i browse to and back to page.
<asp:GridView ID="GridViewSmsComplaints" AllowPaging="True" PageSize="4" runat="server" AutoGenerateColumns="False" CssClass="mGrid" BorderColor="#333333" Width="550px" OnPageIndexChanging="GridViewSmsComplaints_PageIndexChanging" >
<Columns>
<asp:BoundField HeaderText="ID" DataField="ID" />
<asp:BoundField HeaderText="Recieving Date" DataField="RecievingDate" />
<%--<asp:BoundField HeaderText="ToMobileNo" DataField="ToMobileNo" /> --%>
<asp:BoundField HeaderText="FromMobileNo" DataField="FromMobileNo" />
<asp:BoundField HeaderText="Message" DataField="Message" >
<ItemStyle Wrap="True" />
</asp:BoundField>
<asp:TemplateField HeaderText="IsComplaint">
<ItemTemplate>
<asp:CheckBox ID="ckboxIsComplaint" runat="server" Checked='<%# Convert.ToBoolean(Eval("IsComplaint").ToString()) %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
please check the above link.here your problem was clearly explained here.i think so it may be helpfull
As per comments...
If you do not update the underlying database by processing the OnCheckChanged event of the check box, then it will simply be reading the same data all the time.
From How to add event for Checkbox click in Asp.net Gridview Column, I have extracted the required information and tried to modify to fit your initial question.
<asp:TemplateField HeaderText="IsComplaint">
<ItemTemplate>
<asp:CheckBox ID="ckboxIsComplaint" runat="server" Checked='<%# Convert.ToBoolean(Eval("IsComplaint").ToString()) %>' OnCheckedChanged="chk_CheckedChanged" AutoPostBack="true/>
</ItemTemplate>
</asp:TemplateField>
add checkbox change event in aspx.cs page
protected void chk_CheckedChanged(object sender, EventArgs e)
{
GridViewRow row = ((GridViewRow)((CheckBox)sender).NamingContainer);
<your data source>.Rows[row.DataItemIndex]["B"] = ((CheckBox)GridViewSmsComplaints.Rows[row.RowIndex].FindControl("ckboxIsComplaint")).Checked;
}

Hide parent column in Telerik NestedHierarchy

I have a grid similar to the below one, mine has a few more data columns.
I would like to hide ID and ParentID columns. But if I hide ID, Expand/Collapse functionality ceases to exist. All rows are displayed as in a normal table.
How do I achieve it?
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" OnColumnCreated="RadGrid1_ColumnCreated"
OnItemCreated="RadGrid1_ItemCreated" OnItemDataBound="RadGrid1_ItemDataBound" AutoGenerateColumns="false" OnPreRender="RadGrid1_PreRender">
<MasterTableView HierarchyDefaultExpanded="true" HierarchyLoadMode="Client" AllowSorting="false"
DataKeyNames="OrderId, MasterId" Width="100%">
<SelfHierarchySettings ParentKeyName="MasterId" KeyName="OrderId" MaximumDepth="1" />
<Columns>
<telerik:GridTemplateColumn HeaderText="Order ID" UniqueName="OrderId" Display="false">
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Name">
<ItemTemplate><%# Eval("Name") %></ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Number">
<ItemTemplate><%# Eval("PassengerNumber") %></ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Total">
<ItemTemplate><%# Eval("Total") %></ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
<ClientSettings AllowExpandCollapse="true" />
</telerik:RadGrid>
Display="false" still keeps OrderID in the html, so this functionality should work, but it doesn't.
Any idea anyone?
Ok. I've found a solution after taking a closer look at code behind.
In my case, I wanted Expand-Collapse button on Name column.
For that:
In .aspx file, I had to add Name to DataKeyNames. Removed ID & ParentId grid columns. Added UniqueName attribute to Name gridcolumn with value Name.
In code behind, I have passed Name for uniquecolumnname when creating Expand-Collapse button.

GridView Sorting is not working

Merged with GridView sorting works once only.
Please help me, I set Allowsorting="true" but sorting is not working in my GridView. I want automatic sorting i.e. sorting without handling its event.
Here is code of aspx page:
<asp:GridView ID="gdvSignatureLines" runat="server" CssClass="Grid1" AutoGenerateColumns="False"
SkinID="PagedGridView" AllowPaging="True" AllowSorting="True" DataKeyNames="Id"
onrowcommand="gdvSignatureLines_RowCommand"
onrowdeleting="gdvSignatureLines_RowDeleting"
onrowediting="gdvSignatureLines_RowEditing">
<PagerStyle CssClass="gridPager" HorizontalAlign="Right" />
<Columns>
<ucc:commandfieldcontrol headertext="Actions" showdeletebutton="true" buttontype="Image"
deleteimageurl="~/App_Themes/Default/images/delete.png" showeditbutton="true"
editimageurl="~/App_Themes/Default/images/edit.png" deleteconfirmationtext="Are you sure you want to delete?">
<ItemStyle HorizontalAlign="Center" Width="60px" />
</ucc:commandfieldcontrol>
<asp:BoundField DataField="SortOrder" HeaderText="Line" SortExpression="SortOrder" />
<asp:TemplateField HeaderText="Type">
<ItemTemplate>
<asp:Label ID="lblglTypeId" runat="server" Text='<%# Eval("GeneralLookup.LookupItem") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Label">
<ItemTemplate>
<asp:Label ID="lblglLabelId" runat="server" Text='<%# Eval("GeneralLookup1.LookupItem") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Caption" HeaderText="Caption" SortExpression="Caption" />
</Columns>
<EmptyDataTemplate>
<div class="divEmptyListingGrid">
--- No Signature Line Exists ---
</div>
</EmptyDataTemplate>
</asp:GridView>
Here is the code of CS file:
protected void LoadSignatureList(int reportId, string reportName)
{
lblHeading.Text = "Signature Line for " + reportName;
ReportOptionsBO reportOptionsBO = new ReportOptionsBO();
this.gdvSignatureLines.DataSource = reportOptionsBO.GetReportSignatureLineByReportId(reportId);
this.gdvSignatureLines.DataBind();
}
When I click on the Header of column "Line" or "Caption", nothing happens.
I have one more grid that is working fine. The difference between both is, data is bound to this grid on runtime. But the other grid's datasource is preset.
My current grid has not these options of Enable Paging and Enable Sorting.
Please help as soon as possible.

Categories

Resources