how to export images to excel from gridview in asp.net? - c#

I have a ASPxGridView consist of a image column. When I click the ExportToPDF,images are shown in pdf. But if I click the ExportToXls, images are not shown in the excel. What is the problem ?
I use Devexpress 14.2 in visual studio.
P.S. = Images in gridview are different sizes.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td style="padding-right: 4px">
<dx:ASPxButton ID="btnPdfExport" runat="server" Text="Export to PDF" OnClick="btnPdfExport_Click" />
</td>
<td style="padding-right: 4px">
<dx:ASPxButton ID="btnXlsExport" runat="server" Text="Export to XLS" OnClick="btnXlsExport_Click" />
</td>
<td style="padding-right: 4px">
<dx:ASPxButton ID="btnXlsxExport" runat="server" Text="Export to XLSX" OnClick="btnXlsxExport_Click" />
</td>
<td style="padding-right: 4px">
<dx:ASPxButton ID="btnRtfExport" runat="server" Text="Export to RTF" OnClick="btnRtfExport_Click" />
</td>
<td>
<dx:ASPxButton ID="btnCsvExport" runat="server" Text="Export to CSV" OnClick="btnCsvExport_Click" />
</td>
</tr>
</table>
<dx:ASPxGridView ID="Grid" runat="server" AutoGenerateColumns="False" DataSourceID="XmlDataSource1">
<Columns>
<dx:GridViewDataTextColumn FieldName="Common_Name" Caption="Common name" />
<dx:GridViewDataTextColumn FieldName="Species_Name" Caption="Species name" />
<dx:GridViewDataImageColumn FieldName="ImagePath" Caption="Image">
<PropertiesImage>
<ExportImageSettings Width="180" Height="120" />
</PropertiesImage>
</dx:GridViewDataImageColumn>
</Columns>
<SettingsPager PageSize="30" />
</dx:ASPxGridView>
<dx:ASPxGridViewExporter ID="GridExporter" runat="server" GridViewID="Grid" OnRenderBrick="GridExporter_RenderBrick" />
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/Intranet/denemebru/Fishes.xml" />
</form>
</body>
</html>

public partial class Intranet_denemebru_RaporDeneme2 : System.Web.UI.Page
{
protected void GridExporter_RenderBrick(object sender, ASPxGridViewExportRenderingEventArgs e)
{
var dataColumn = e.Column as GridViewDataColumn;
if (dataColumn != null && dataColumn.FieldName == "ImagePath" && e.RowType == GridViewRowType.Data)
e.ImageValue = GetImageBinaryData(e.Value.ToString());
}
protected void btnPdfExport_Click(object sender, EventArgs e)
{
GridExporter.WritePdfToResponse();
}
protected void btnXlsExport_Click(object sender, EventArgs e)
{
GridExporter.WriteXlsToResponse();
}
protected void btnXlsxExport_Click(object sender, EventArgs e)
{
GridExporter.WriteXlsxToResponse();
}
byte[] GetImageBinaryData(string relativePath)
{
string path = Server.MapPath(relativePath);
return File.Exists(path) ? File.ReadAllBytes(path) : null;
}
}

Related

Even If I wrote all the code, After checking the checkboxes nothing is being added to the listbbox

SERVER SIDE SCRIPT
I wrote this code to make a web form that ADDS or REMOVES items in the Listbox when the checkbox is checked or unchecked but even after checking and unchecking the checkboxes nothing is happening.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 250px;
}
</style>
</head>
<body style = "background-color:darksalmon; font-style:oblique; font-family:'Gill Sans MT'">
<form id="form1" runat="server">
<div>
<center>
<table border="3" border-color="black">
<tr>
<td colspan="2" border="2" align="center">
<asp:ListBox ID="ListBox1" runat="server" Height="414px" Width="316px"></asp:ListBox>
</td>
<td class="auto-style1">
<asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged" Text="PHP" />
<br />
<br />
<asp:CheckBox ID="CheckBox2" runat="server" OnCheckedChanged="CheckBox2_CheckedChanged" Text="JAVA" />
<br />
<br />
<asp:CheckBox ID="CheckBox3" runat="server" OnCheckedChanged="CheckBox3_CheckedChanged" Text="C" />
</td>
</tr>
</table>
</center>
</div>
</form>
</body>
</html>
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
if(CheckBox1.Checked == true)
{
ListBox1.Items.Add(CheckBox1.Text);
}
else
{
ListBox1.Items.Remove(CheckBox1.Text);
}
}
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox2.Checked == true)
{
ListBox1.Items.Add(CheckBox2.Text);
}
else
{
ListBox1.Items.Remove(CheckBox2.Text);
}
}
protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox3.Checked == true)
{
ListBox1.Items.Add(CheckBox3.Text);
}
else
{
ListBox1.Items.Remove(CheckBox3.Text);
}
}
I tried to change the coding at "protected-void CheckBox1_CheckedChanged(object sender, EventArgs e)"
but nothing is being added to the list even after checking the checkbox.!!

opening a new window in .net to display an image

We have added a new gallery page to our website, which displays a series of thumbnails using
We would like to display popup window to display the image in a larger format and have used the following code so far -
ScriptManager.RegisterStartupScript(Me, GetType(String), "New_Window", "window.open('" & webUrl & "Cacique4.jpg', null, 'height=400,width=400,status=yes,toolbar=yes,menubar=yes,location=no' );", True)
The window displays like a normal browser only sized to 400x400.
Is there any way to display the image in a pop up window?
Here's an example:
ASPX:
<head runat="server">
<title>Modal Popup</title>
<style type="text/css">
.modalStyle
{
background-color: Gray;
filter: alpha(opacity=70);
opacity: 0.7;
}
.panelStyle
{
width: 300px;
height: 180px;
border: 2px solid Gray;
background-color:White;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="scripManager" runat="server" />
<asp:ModalPopupExtender ID="modal" CancelControlID="btnCancel" BackgroundCssClass="modalStyle" PopupControlID="popup" TargetControlID="lblPopup" runat="server" />
<asp:Label ID="lblPopup" runat="server" />
<asp:Panel runat="server" ID="popup" CssClass="panelStyle">
<table style="width: 100%;">
<tr>
<td>
<asp:RadioButton ID="rdboption1" AutoPostBack="true" OnCheckedChanged="CheckedChanged" runat="server" Text="Option 1" GroupName="Options" /><br />
<asp:RadioButton ID="rdboption11" runat="server" Text="Option 1.1" GroupName="SubOption1"
Visible="false" /><br />
<asp:RadioButton ID="rdboption12" runat="server" Text="Option 1.2" GroupName="SubOption1"
Visible="false" />
</td>
</tr>
<tr>
<td>
<asp:RadioButton ID="rdboption2" AutoPostBack="true" OnCheckedChanged="CheckedChanged" runat="server" Text="Option 2" GroupName="Options" /><br />
<asp:RadioButton ID="rdboption21" runat="server" Text="Option 2.1" GroupName="SubOption2"
Visible="false" /><br />
<asp:RadioButton ID="rdboption22" runat="server" Text="Option 2.2" GroupName="SubOption2"
Visible="false" />
</td>
</tr>
<tr>
<td style="text-align: center;">
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</td>
</tr>
</table>
</asp:Panel>
</form>
</body>
Code behind:
public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
modal.Show();
}
protected void CheckedChanged(object sender, EventArgs e)
{
var radioButton = sender as RadioButton;
ResetOptions();
switch(radioButton.ID)
{
case "rdboption1":
rdboption11.Visible = true;
rdboption12.Visible = true;
break;
case "rdboption2":
rdboption21.Visible = true;
rdboption22.Visible = true;
break;
}
}
private void ResetOptions()
{
rdboption11.Visible = false;
rdboption12.Visible = false;
rdboption21.Visible = false;
rdboption22.Visible = false;
}
}

Change ASPxGridView SettingsLoadingPanel text dynamically

I need to change ASPxGridView SettingsLoadingPanel dynamically (from code behind if is possible).
For example, when I clicked on checkbox I want text to be 'selecting...' and after click the button to see text 'loading...'
Thanks!
You can use ASPxClientLoadingPanel method. And also .Shov() method invokes the loading panel.
<dxlp:ASPxLoadingPanel ID="ASPxLoadingPanel1" runat="server" ClientInstanceName="lp">
</dxlp:ASPxLoadingPanel>
<dxe:ASPxButton ID="btnShow" runat="server" AutoPostBack="False"
Text="Show" ClientInstanceName="button" >
<ClientSideEvents Click="function(s, e) {
lp.Show();
}" />
</dxe:ASPxButton>
<dxe:ASPxButton ID="btnHide" runat="server" AutoPostBack="False"
Text="Hide" ClientInstanceName="button" >
<ClientSideEvents Click="function(s, e) {
lp.Hide();
}" />
</dxe:ASPxButton>
Also you can find a demo in this link.
ASPX
<%# Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Example.aspx.cs"
Inherits="ASPxLoadingPanel_Example" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentHolder" runat="Server">
<dx:ASPxCallback ID="ASPxCallback1" runat="server" ClientInstanceName="Callback">
<ClientSideEvents CallbackComplete="function(s, e) { LoadingPanel.Hide(); }" />
</dx:ASPxCallback>
<div class="BottomPadding">
<dx:ASPxCheckBox ID="ASPxCheckBox1" runat="server" AutoPostBack="true" Checked="True"
Text="Display the ASPxLoadingPanel over a specific control">
</dx:ASPxCheckBox>
</div>
<table id="Panel" style="border: Dashed 1px Gray; height: 125px; width: 60%; margin: 30px 20%">
<tr>
<td align="center" valign="middle">
<dx:ASPxButton ID="ASPxButton1" runat="server" Text="Show Loading Panel" AutoPostBack="False">
<ClientSideEvents Click="function(s, e) {
Callback.PerformCallback();
LoadingPanel.Show();
}" />
</dx:ASPxButton>
</td>
</tr>
</table>
<dx:ASPxLoadingPanel ID="LoadingPanel" runat="server" ClientInstanceName="LoadingPanel"
Modal="True">
</dx:ASPxLoadingPanel>
</asp:Content>
C#
using System;
using System.Threading;
using System.Web.UI;
public partial class ASPxLoadingPanel_Example : Page {
protected void Page_Load(object sender, EventArgs e) {
if(IsCallback) {
// Intentionally pauses server-side processing,
// to demonstrate the Loading Panel functionality.
Thread.Sleep(500);
}
LoadingPanel.ContainerElementID = ASPxCheckBox1.Checked ? "Panel" : "";
}
}

div tag visible attribute is not working

I use web control in asp.net using c#. I use div tag. on btnProviderSubmit1 i change visibility of divprov. but divprov is not visible false. It visible.
pos.ascx
<%# Control Language="C#" AutoEventWireup="true" CodeFile="pos.ascx.cs" Inherits="USerControls_Recharge_pos" %>
<%# Register Assembly="Gaia.WebWidgets" Namespace="Gaia.WebWidgets" TagPrefix="gaia" %>
<form id="Form1" runat="server">
<div>
<div>
<asp:LinkButton runat="server" ID="moveTo" Text="Go To Classical Mode" PostBackUrl="~/DesktopModules/Recharge/Recharge.aspx" OnClick="SaveCookies"/>
</div>
<div title="Select Provider" id="divprov" **visible="true"** runat="server" style="border-width:medium;border-color:Blue;border-width:medium;">
<asp:ListView DataSourceID="ObjectDataSource1" GroupItemCount="12" GroupPlaceholderID="groupPlaceholder" ItemPlaceholderID="itemPlaceholder" ID="ddlprovider" runat="server">
<LayoutTemplate >
<table runat="server" id="table2" style="border-width:medium" cellpadding="3">
<tr runat="server" id="groupPlaceholder">
</tr>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr runat="server" id="productRow" style="height:80px">
<td runat="server" id="itemPlaceholder">
</td>
</tr>
</GroupTemplate>
<ItemTemplate>
<td id="Td2" valign="top" align="center" style="width:100" runat="server">
<gaia:ImageButton runat="server" CommandArgument='<%#Eval("providerID") %>' **OnCommand="btnProviderSubmit1"** ImageUrl='<%# getImageURL(Eval("providerCode")) %>' ID="ImageButton1" /><br />
<gaia:LinkButton runat="server" CommandArgument='<%#Eval("providerID") %>' OnCommand="btnProviderSubmit1" Text='<%#Eval("description") %>' ID="lnkButton1"/>
</td>
</ItemTemplate>
</asp:ListView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DeleteMethod="Delete" InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}" SelectMethod="FetchAll"
TypeName="mogile.MidTier.DAL.ProviderController" UpdateMethod="Update">
</asp:ObjectDataSource>
</div>
<div>
<gaia:Panel runat="server" ID="pnlCircle" Visible="false" ScrollBars="Auto">
<asp:ListView ID="ddlCircle" GroupItemCount="8" GroupPlaceholderID="groupPlaceholder" ItemPlaceholderID="itemPlaceholder" runat="server" DataSourceID="ObjectDataSource2">
<LayoutTemplate>
<table runat="server" id="table2" cellpadding="3">
<tr runat="server" id="groupPlaceholder">
</tr>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr runat="server" id="tableRow">
<td runat="server" id="itemPlaceholder" />
</tr>
</GroupTemplate>
<ItemTemplate>
<td id="Td1" runat="server">
<gaia:LinkButton ID="LinkButton1" OnCommand="btnCircleSubmit" Font-Size="Larger" BorderColor="red" BorderWidth="4px" runat="server" CommandArgument='<%#Eval("StateID") %>' Text='<%#Eval("StateName") %>'/>
</td>
</ItemTemplate>
</asp:ListView>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server"
DeleteMethod="Delete" InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}" SelectMethod="FetchAll"
TypeName="mogile.MidTier.DAL.StateController" UpdateMethod="Update">
</asp:ObjectDataSource>
</gaia:Panel>
</div>
</div></form>
pos.ascx.cs
public partial class USerControls_Recharge_pos : System.Web.UI.UserControl
{
private static int itemid = 0;
private static string circleCode;
private static string pdfText;
private static string providerName;
private static string productGrp;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnProviderSubmit1(object sender, CommandEventArgs e)
{
providerName = e.CommandArgument.ToString();
loadProductGroups(e.CommandArgument.ToString());
pnlCircle.Visible = true;
**divprov.Visible = false;**
}
protected void btnCircleSubmit(object sender, CommandEventArgs e)
{
circleCode = e.CommandArgument.ToString();
pnlProductGrp.Visible = true;
// pnlCircle.ForceAnUpdate();
}
}
A workaround could probably be to add "display:none" (or was it "visibility:hidden"? - you can google here) to the style attribute programatically in the btnClick handler.

Gridview not visible even after binding

I got stucked to some weird condition where I have a gridview inside a ajax toolkit tabcontainer. On tab index change i am binding grid. But nothing happend. Grid is not appearing. I have check the following
Viewstate
Visibility of grid
Visibility of the parent table.
Data is coming from the method
visibility of the tab panel
Even i have debugged and added watch to check if its getting null before loading the page.
Please help me out
** BELOW IS THE UPDATED CODE**
<HTMLCode>
<Toolkit:TabPanel HeaderText="Pending Challans" ID="tpPendingChallan" runat="server" Height="200px" >
<ContentTemplate>
<table style="width: 100%">
<tr>
<td>
<asp:GridView ID="gvPendingChallans" runat="server" AutoGenerateColumns="True" CellPadding="4" Width="100%" OnPageIndexChanging="gvPendingChallans_PageIndexChanging"
OnRowCommand="gvPendingChallans_RowCommand" AllowPaging="True" GridLines="None">
</asp:GridView>
</td>
</tr>
</table>
</ContentTemplate>
</Toolkit:TabPanel>
</HTMLCode>
========================================================================
<C#>
private void BindPendingChallans()
{
var dat = JobCardManager.DisplayChallan();
gvPendingChallans.DataSource = dat;
gvPendingChallans.DataBind();
}
protected void tcMembers_ActiveTabChanged(object sender, EventArgs e)
{
if(tcMembers.ActiveTabIndex == 6)
{
BindPendingChallans();
}
}
</C#>
Sorry for miss interpretation of your code with my first answer. I thought that it just a simple population of grid view, but as review I found that you are using the Ajax Toolkit library and your grid is inside the tab selection. You can try this:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="Toolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head2" runat="server">
<title>Untitled Page</title>
<style type="text/css">
.style1
{
font-family: Arial;
color: #3399FF;
}
</style>
</head>
<body class="style1">
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager2" runat="server" EnablePageMethods="true" />
<div>
<asp:UpdatePanel ID="upMember" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<table cellpadding="1" cellspacing="4" border="0" width="100%">
<tr>
<td>
<Toolkit:TabContainer ID="tcMembers" runat="server" AutoPostBack="true"
ActiveTabIndex="0" onactivetabchanged="tcMembers_ActiveTabChanged">
<Toolkit:TabPanel HeaderText="Pending Challans" ID="tpPendingChallan" runat="server"
Height="200px">
<ContentTemplate>
<asp:GridView ID="gvPendingChallans" runat="server" AutoGenerateColumns="True" CellPadding="4"
Width="100%" OnPageIndexChanging="gvPendingChallans_PageIndexChanging" OnRowCommand="gvPendingChallans_RowCommand"
AllowPaging="True" GridLines="None">
</asp:GridView>
</ContentTemplate>
</Toolkit:TabPanel>
<Toolkit:TabPanel HeaderText="Pending 2" ID="tpPending2" runat="server"
Height="200px">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="True" CellPadding="4"
Width="100%" OnPageIndexChanging="gvPendingChallans_PageIndexChanging" OnRowCommand="gvPendingChallans_RowCommand"
AllowPaging="True" GridLines="None">
</asp:GridView>
</ContentTemplate>
</Toolkit:TabPanel>
</Toolkit:TabContainer>
</td>
<td width="2%">
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
Then in your code behind:
protected void Page_Load(object sender, EventArgs e)
{
upMember.Update();
}
private void BindPendingChallans()
{
//var dat = JobCardManager.DisplayChallan();
//gvPendingChallans.DataSource = dat; gvPendingChallans.DataBind();
}
protected void tcMembers_ActiveTabChanged(object sender, EventArgs e)
{
if (tcMembers.ActiveTabIndex == 6)
{
BindPendingChallans();
}
}
protected void gvPendingChallans_PageIndexChanging(object sender, GridViewPageEventArgs e){
}
protected void gvPendingChallans_RowCommand(object sender, GridViewCommandEventArgs e){
}
Note: That in you 'tcMembers_ActiveTabChanged' you had specify tab index 6
The Tab index begins with 0. Maybe you can adjust it depending the number of
you Intended tab....
Regards,

Categories

Resources