Archive for December, 2008
Export Data from Data Table to Excel File Format using C#.NET
In order to achieve this first, you need to add a component known as Excel.dll (Microsoft excel 11.0 Object Library) into your .NET project references.
To do above follow below instructions:
Add a reference to the Microsoft Excel Object Library. To do this, follow these steps:
a. On the Project menu, click Add Reference.
b. On the COM tab, locate Microsoft Excel 11.0 Object Library, and then click Select.
c. Click OK in the Add References dialog box to accept your selections. If you receive a prompt to generate wrappers for the libraries that you selected, click yes.
No comments
Validating Controls within Ajax Tab Panels/Tab Control
Normally when we are using Ajax TabContols in aspx page with validation controls enabled on each and every TabPanel. Suppose if iam having 3 tab panels in TabControl and every tabpanel has some validations enabled and if iam in 1st panel and I submitted the form by clicking the button and in the 1st panel every thing is ok i.e. I filled all my required fields on the 1st TabPanel. But I left some fields blank on the 2nd and 3rd TabPanel; when you click on submit button the validations will be enabled on 2nd and 3rd panel but the tab index of the TabControl will be still on the 1st TabPanel only. But we want TabIndex to automatically change based on the validation failed on the TabPanel. In order to do that we have to write a piece of JavaScript as show below:
<script type=”text/javascript”>
var handleTabChange = true;
function ValidatePage()
{
if(handleTabChange)
{
if (Page_ClientValidate(‘Tab1′) == false)
{
$find(“<%=TabContainerAddEnquiry.ClientID%>”).set_activeTabIndex(0);
}
else if (Page_ClientValidate(‘Tab2′) == false)
{
$find(“<%=TabContainerAddEnquiry.ClientID%>”).set_activeTabIndex(1);
}
else if (Page_ClientValidate(‘Tab3′) == false)
{
$find(“<%=TabContainerAddEnquiry.ClientID%>”).set_activeTabIndex(2);
}
}
else
{
handleTabChange = true;
}
}
</script>
No comments
Maintain tab index on Ajax tab control with post back
I have a DropDownList in 2 different Tab Panels in a TabContainer (from the AJAX control toolkit on ASP.NET’s website) and I discovered that the TabContainer does not maintain state on postbacks for DropDownLists. In other words, if I am on the second tab and I changed the value of the DropDownList (w/ AutoPostBack=”true”), I always return to the first tab (index 0).
In order to solve the above problem, we have to write a piece of Code in JavaScript as show below:
<script type=”text/javascript”>
function SaveActiveTabIndex(sender, e)
{
var activetabindex = sender.get_activeTab().get_tabIndex();
setCookie(activetabindex);
}
function setCookie(value)
{
document.cookie = “tabIndex=” + escape(value) ;
}
</script>
No comments
Exporting GridView to Excel Problem When Using Web UserControl:
This article explains how you can export your GridView control to Excel files. If you are working with web user control. Suppose if you are having your gridview in your User Control and you are trying to export the gridview data to some other format some thing like this
protected void _btnReports_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Write(@”<!DOCTYPE HTML PUBLIC “”-//W3C//DTD HTML 4.0 Transitional//EN”">”);
Response.AddHeader(“content-disposition”, “inline;filename=search_topicarea.doc”);
Response.Charset = “”;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = “application/vnd.doc”;
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
//System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
//Render(htmlWrite);
_gvViewresults.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
No comments
Exporting GridView to Excel ‘GridView’ must be placed inside a form tag
This article explains how you can export your GridView control to Excel files. If you are working with GridView.
Exporting Grid View to Excel Files:
The approach is pretty much the same as it was in Gridview. The following code executes on a button click event.
protected void _btnReports_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Write(@”<!DOCTYPE HTML PUBLIC “”-//W3C//DTD HTML 4.0 Transitional//EN”">”);
Response.AddHeader(“content-disposition”, “inline;filename=search_topicarea.doc”);
Response.Charset = “”;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = “application/vnd.doc”;
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
//System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
//Render(htmlWrite);
_gvViewresults.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
No comments
