Telerik after filtering radgrid export buttons not working - vb.net

I am working with telerik, and want to export data from radgrid in my vb.net web application. After filter grid, when click on export button, nothing works and itemCommand header(refresh button, export buttons) hide automatically.
But export grid without filter , working perfectly.
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="radgrid1_NeedDataSource" ShowStatusBar="true" AllowPaging="True" Skin="Windows7" AllowCustomPaging="false" PageSize="25" GridLines="None" AutoGenerateColumns="false" AllowSorting="true" AllowColumnResize="true">
<PagerStyle Mode="NextPrevNumericAndAdvanced"></PagerStyle>
<MasterTableView Width="100%" CommandItemDisplay="Top" ShowHeader="true">
<Columns>
<telerik:GridBoundColumn DataField="assettagnumber" HeaderText="Tag Number" SortExpression="assettagnumber" UniqueName="assettagnumber">
<HeaderStyle Width="80px" />
</telerik:GridBoundColumn>
</Columns>
<CommandItemSettings ShowExportToWordButton="true" ShowAddNewRecordButton="false" ShowExportToExcelButton="true" ShowExportToPdfButton="false" ShowExportToCsvButton="true" />
</MasterTableView>
<ExportSettings IgnorePaging="true" OpenInNewWindow="true" ExportOnlyData="true">
</ExportSettings>
<ClientSettings>
<Scrolling AllowScroll="True" EnableVirtualScrollPaging="false" SaveScrollPosition="True" UseStaticHeaders="True" />
</ClientSettings>
</telerik:RadGrid>
I want to export filtered grid data.
Please tell me the possible solution.
Thanks..

Related

RadButton stays visible on the page all the time after Radgrid reload

I have a page where I search the data and populate RadGrid.
The page has a button to export the data into Excel.
Everything works fine, data is exporting. I can search as well.
I hide the button and RadGrid in the code when the Grid is empty:
btnExport.Visible = false;
gridDisplay.Visible = false;
However, when RadGrid is empty, it becomes hidden but button is still displayed.
I build the RadGrid inside of the RadAjaxPanel:
<telerik:RadAjaxPanel ID="RadAjaxPanel2" runat="server" LoadingPanelID="RadAjaxLoadingPanel2">
<telerik:RadGrid
RenderMode="Lightweight"
runat="server"
ID="grdMoss2Merchants"
AllowPaging="True"
AllowSorting="true"
PagerStyle-AlwaysVisible="true"
OnNeedDataSource="BindToDatasource"
OnSortCommand="grdMoss2Merchants_SortCommand"
ViewStateMode="Enabled"
AutoGenerateColumns="false"
OnPageIndexChanged="grdMoss2Merchants_ChangePage"
ClientSettings-Scrolling-ScrollHeight="360px">
<GroupingSettings CaseSensitive="false"/>
<ExportSettings HideStructureColumns="true" ExportOnlyData="true" OpenInNewWindow="true" Excel-Format="Xlsx" IgnorePaging="true" FileName="Moss2Merchants">
<Excel WorksheetName="Moss2Merchants" Format="Xlsx" AutoFitColumnWidth="AutoFitAll" />
</ExportSettings>
<ClientSettings EnableRowHoverStyle="true">
<Scrolling AllowScroll="true" UseStaticHeaders="True"/>
<ClientEvents OnKeyPress="keyPress" />
</ClientSettings>
<SortingSettings EnableSkinSortStyles="false" />
<HeaderStyle Width="160px" CssClass="grdHeader" ForeColor="#2E6E9E" />
<MasterTableView AllowNaturalSort="false">
<PagerStyle AlwaysVisible="true" Mode="NextPrevAndNumeric" PageSizes="10,25,50,100" />
<Columns>
<telerik:GridBoundColumn DataField="Moss2 MID" HeaderText="MOSS2 MID" AllowSorting="false" DataFormatString="{0:#}"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="DBA" HeaderText="DBA" HeaderStyle-Width="250px">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Original MID" HeaderText="ORIGINAL MID" AllowSorting="false" DataFormatString="{0:#}"></telerik:GridBoundColumn>
<telerik:GridBoundColumn
DataField="BoardingDate"
DataType="System.DateTime"
HtmlEncode="false"
DataFormatString="{0:MM/dd/yyyy}"
SortExpression="BoardingDate"
UniqueName="BoardingDate"
HeaderText="BOARDING DATE"
HeaderStyle-Width="170px"
ShowFilterIcon="false"
/>
<telerik:GridBoundColumn DataField="Status" HeaderText="STATUS" AllowSorting="false"></telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</telerik:RadAjaxPanel>
This just a simple code to generate a button outside of the Grid:
<div>
<telerik:RadButton ID="btnExport" runat="server" OnClick = "btnExportClick" Text="Export To Excel" CausesValidation="false"/>
<br/>
</div>
I'm not sure what I'm doing wrong here.
Need some assistance

GridView SelectParameter from code behind

I am using VB.NET webforms.
I have a GridView which brings data from Database when the page loads. The SQLDataSource with Select SQL is as follows:
<asp:SqlDataSource
ID="ScopeDataSource"
runat="server"
ConnectionString="<%$ ConnectionStrings:SQLServerConnectionString %>"
SelectCommand="SELECT [SCO_LINENUM], [SCO_LINETEXT], [SCO_SCOPEID], [SCO_TAB1LINK], [SCO_TAB2LINK], [SCO_TAB3LINK] FROM [SCOPE] WHERE [SCO_SCOPEID] = 'AAAREN02'"></asp:SqlDataSource>
My GridView is as follows:
<asp:GridView
ID="ScopeGrid"
runat="server"
DataSourceID="ScopeDataSource"
AutoGenerateColumns="False"
GridLines="None"
DataKeyNames="SCO_SCOPEID, SCO_LINENUM">
<Columns>
<asp:BoundField DataField="SCO_LINENUM" HeaderText="Sr#" SortExpression="SCO_LINENUM">
<HeaderStyle Height="40px" />
<ItemStyle Width="30px" />
</asp:BoundField>
<asp:BoundField DataField="SCO_LINETEXT" HeaderText="Parameter.." SortExpression="SCO_LINETEXT">
<HeaderStyle Height="40px" />
<ItemStyle Width="100px" />
</asp:BoundField>
<asp:TemplateField HeaderText="Operator Values...........">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" CssClass="DropDownMargin">
<asp:ListItem>BETWEEN</asp:ListItem>
<asp:ListItem>EQUALTO</asp:ListItem>
<asp:ListItem>GREATERTHAN</asp:ListItem>
<asp:ListItem>LESSTHAN</asp:ListItem>
</asp:DropDownList>
<asp:TextBox runat="server" ID="RangeStart" Text="None" Width="50px" CssClass="TextBoxMargin"></asp:TextBox>
<asp:TextBox runat="server" ID="RangeEnd" Text="None" Width="50px"></asp:TextBox>
</ItemTemplate>
<HeaderStyle Height="40px" CssClass="WhiteSpacePreserve" />
</asp:TemplateField>
<asp:BoundField DataField="SCO_SCOPEID" HeaderText="ScopeID" SortExpression="SCO_SCOPEID">
<HeaderStyle CssClass="hidegrid" />
<ItemStyle CssClass="hidegrid" />
</asp:BoundField>
<asp:BoundField DataField="SCO_TAB1LINK" HeaderText="Tab1" SortExpression="SCO_TAB1LINK" />
<asp:BoundField DataField="SCO_TAB2LINK" HeaderText="Tab2" SortExpression="SCO_TAB2LINK" />
<asp:BoundField DataField="SCO_TAB3LINK" HeaderText="Tab3" SortExpression="SCO_TAB3LINK" />
</Columns>
</asp:GridView>
As seen in above SQLDataSource, the WHERE clause is hard-coded. I want to make this dynamic by passing a variable to the WHERE clause from code-behind. Also My Page_Load event is empty. So far, since the SQLDataSource WHERE clause is hard-coded in my aspx I can see the data in gridview but I don't know how to send a variable to it from code-behind?
Something like this would work.
Change your select command to
SELECT [SCO_LINENUM], [SCO_LINETEXT], [SCO_SCOPEID], [SCO_TAB1LINK], [SCO_TAB2LINK], [SCO_TAB3LINK] FROM [SCOPE] WHERE [SCO_SCOPEID] = #SCO_SCOPEID
Then do like
ScopeDataSource.SelectParameters("SCO_SCOPEID").DefaultValue = Your value

RadGrid change column header not working

I am trying to change the column header. When I do so it does not show the radgrid at all. If I comment the code inside of rdMain_PreRender the grid show up fine. Am I doing something wrong.
<telerik:RadGrid runat="server" ID="rdMain" AutoGenerateColumns="false" AllowPaging="true" Skin="Metro" OnPreRender="rdMain_PreRender" DataSourceID="MainSource" AllowAutomaticUpdates="true" AllowAutomaticDeletes="true">
<MasterTableView DataKeyNames="ID" CommandItemDisplay="None">
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" />
<telerik:GridBoundColumn DataField="Location" HeaderText="Location" ReadOnly="true" />
<telerik:GridBoundColumn DataField="Name" HeaderText="Name" />
<telerik:GridBoundColumn DataField="Phone" HeaderText="Phone" />
<telerik:GridButtonColumn ConfirmText="Delete?" ConfirmDialogType="RadWindow"
ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" />
</Columns>
<EditFormSettings>
<EditColumn ButtonType="ImageButton" />
</EditFormSettings>
</MasterTableView>
<PagerStyle Mode="NextPrevAndNumeric" />
</telerik:RadGrid>
protected void rdMain_PreRender(object sender, EventArgs e)
{
var masterTableView = rdMain.MasterTableView;
var column = masterTableView.GetColumn("Phone");
column.HeaderText = "TelePhone";
masterTableView.Rebind();
}
Set the unique name of the columns in the grid and try using the next line of code in PreRender:
rdMain.Columns.FindByUniqueName("Phone").HeaderText = "TelePhone";
Hope it works.

very strange issue; different results from same table

I am binding a gridview with some column from a database table, but it shows different results in Pane and in Gridview. see the attachted images.
see the marked records why they are different, although they are comming from the same table.
But yes for binding gridview I am using this query
SELECT mtblbuilding_budget_data.building_id,
mtblbuilding_budget_data.building_name,
mtblbuilding_budget_data.sanctioned_dpr,
mtblbuilding_budget_data.sanctioned_contract,
mtblblock.block_name
FROM mtblbuilding_budget_data
LEFT JOIN mtblblock
ON mtblblock.block_id = mtblbuilding_budget_data.block_id
WHERE mtblbuilding_budget_data.sfti_id = #SFTI_Id
AND mtblbuilding_budget_data.spmu_id = #SPMU_Id
ORDER BY mtblbuilding_budget_data.block_id
aspx code
<asp:TemplateField HeaderText="Sanction (DPR)">
<ItemTemplate>
<%#GetQTY1(float.Parse(Eval("Sanctioned_DPR").ToString())).ToString("N2")%>
</ItemTemplate>
<FooterTemplate>
<%#GetTotalQTY1().ToString("N2")%>
</FooterTemplate>
<FooterStyle HorizontalAlign="Right" />
<HeaderStyle HorizontalAlign="Right" />
<ItemStyle HorizontalAlign="Right" VerticalAlign="Top" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Sanction (Contract)">
<ItemTemplate>
<%#GetQTY2(float.Parse(Eval("Sanctioned_Contract").ToString())).ToString("N2")%>
</ItemTemplate>
<FooterTemplate>
<%#GetTotalQTY2().ToString("N2")%>
</FooterTemplate>
<FooterStyle HorizontalAlign="Right" />
<HeaderStyle HorizontalAlign="Right" />
<ItemStyle HorizontalAlign="Right" VerticalAlign="Top" />
</asp:TemplateField>
Your grigview is rounding the values, check the next column on the same lines, it also as different results.
check the properties of your gridview e disable the round option.
check the properties of your gridview e disable the round option. That's the solution..

vb.net datatype in manually added column

Dim pctofpax As New DataColumn
pctofpax = New DataColumn("PCTPAX1", GetType(Decimal))
pctofpax.Expression = "[ASOFPAX] / [YEPAX]"
ds.Tables("workplease").Columns.Add(pctofpax)
Dim avgppax As New DataColumn
avgppax = New DataColumn("AVG PAX", GetType(Double))
avgppax.Expression = "[Current Sales] / [Current PAX]"
ds.Tables("workplease").Columns.Add(avgppax)
These are two columns that i added into my asp.net/vb.net datagrid. the problem is i keep trying to change the datatypes so they show up as numbers with only two decimals but it is not working
<span lang="en-us">Sales As Of Analysis</span><br />
<asp:GridView ID="GridView1" runat="server" BackColor="White"
BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3"
GridLines="Vertical">
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#DCDCDC" />
</asp:GridView>
<asp:BoundColumn DataField="PCTPAX1"
HeaderText="PCTPAX1"
DataFormatString="{0:c}">
</div>
</form>
</body>
</html>
and nothing happend to my data
If it's just a matter of displaying only two decimals, this can be accomplished in the display code for the DataGrid:
<asp:BoundField DataField="PCTPAX1"
HeaderText="PCTPAX1"
DataFormatString="{0:c}">
Note the DataFormatString value of {0:c} which specifies that the formatting of the value in that field should be "currency." (You can also try with a capital C, I don't have a test handy for it right now.) There's a lot more you can do with format strings, more information here.
Or do you want the actual values to be rounded to currency values? You'll likely use Math.Round for that, though I don't have an example handy. There's information about that here.
Edit: Based on your comment(s), it sounds like you were attempting to change data types at the database level. This won't really impact the code. The value coming back from the database in the form of a double or decimal or some other numeric likely won't carry that precision back to the code. As far as the DataGrid is concerned, it's calling .ToString() on a double and showing the result. No database data type is involved. Using the DataFormatString property to pass a format string to the .ToString() method is how to change the display.
Edit again based on your question edit: Your HTML is broken. You have the BoundColumn outside of the grid, and the column tag itself isn't closed. Columns go inside the grid. See the grid layout here. Basically, you'd want something more like:
<asp:GridView ID="GridView1" runat="server" BackColor="White"
BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3"
GridLines="Vertical">
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#DCDCDC" />
<Columns>
<asp:BoundField DataField="PCTPAX1"
HeaderText="PCTPAX1"
DataFormatString="{0:c}">
</asp:BoundField>
</Columns>
</asp:GridView>
Changing the type of a column which is already in your datatable doesn't work. or at least not that i know. if you just want to get a different formatting, look at the answers above.