|
Use this :
DataTable dt = datatable1.clone();
foreach(DataColumn dc in datatable2.Columns)
{
DataColumn dc1 = new DataColumn(dc.Caption,dc.DataType);
dt.Columns.add(dc1);
}
foreach(DataColumn dc in datatable3.Columns)
{
DataColumn dc1 = new DataColumn(dc.Caption,dc.DataType);
dt.Columns.add(dc1);
}
Now to merge the data you need to
for(i=0;i<datatable1.rows.count;i++)
{
DataRow drNew = dt.NewRow();
for(j=0;i<dt.columns.count;j++)
{
if(j< datatable1.Columns.count)
drNew[j] = datatable1.rows[i][j];
else if(j<(datatable1.Columns.count + datatable2.Columns.count))
drNew[j] = datatable2.rows[i][j-datatable1.columns.count-1];
...
}
Finally
dt.Rows.Add(drNew)
You can also make it more cleaner. Also change it according to your need.
Hope it works
|
|
|
|
|
Hi,
In asp.net 3.5, how is it possible to
1)Export the data of a datatable into .csv file
2)Save the spreadsheet on the network as c:\temp\
Thanks
|
|
|
|
|
Check the previous thread.Is that you actually looking for?
Else Google.
|
|
|
|
|
|
why use CSV .. Create Original Excel file rather.
Check this :
http://www.codeproject.com/script/Forums/KB/miscctrl/Excel_data_access.aspx
Hope this will help you.
|
|
|
|
|
Hello all,
In my ASP.Net application, i am transferring GridView contents to a excel file. I am using following code:
string attachment = "attachment; filename=MakeList.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
It was working fine, but as soon as i put this code in try-catch block, i am getting this error:
"Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack."
If i remove try-catch block, it again works fine.
Can anyone tell me whats the problem? Am i miising something?
Thanks,
Nagendra.
|
|
|
|
|
|
I tried the solution. Now i am not getting any exception but now instead of GridView contents, the whole WebPage is copied in excel file.
I want only GridView contents in excel file.
|
|
|
|
|
What you have done?
I think you removed Response.End().
|
|
|
|
|
Yes, as mentioned in that post, i used "HttpContext.Current.ApplicationInstance.CompleteRequest()" in place of Response.End()
|
|
|
|
|
Hi All My Friends,
I Have 2 problems in a javascript.
1: I am not getting the Item Count Of Dropdown List.
2: I am calling javascript on Button "OnClientClick" event,then also onclick event is fired even script returning false.
Hav a look on Script
function validate()
{
if (document.getElementById("<%=ddlCategories.ClientID%>").selectedIndex == 0) {
alert("Select a Category name !")
document.getElementById("<%=ddlCategories.ClientID%>").focus()
return false;
}
else if (document.getElementById("<%=txtText.ClientID%>").value == "") {
alert("Please fill the Message field !")
document.getElementById("<%=txtText.ClientID%>").focus()
return false;
}
else {
if (SubcategoryCount > 0) {
if (document.getElementById("<%=ddlCategories.ClientID%>").selectedIndex != 0 && document.getElementById("<%=ddlSubCategories.ClientID%>").selectedIndex == 0) {
alert("Select a Sub-Category name !")
return false;
}
}
}
}
|
|
|
|
|
Sachin Dubey wrote: if (SubcategoryCount > 0) {
Where you got this SubcategoryCount from?
Its good if you can make your code little bit readable to the forum readers.
|
|
|
|
|
That is only i asked in first question.. I Have ddlSubCategories in Page
|
|
|
|
|
Sachin Dubey wrote: That is only i asked in first question
that i know.
What i am asking is, in your code you have a line of code like,SubcategoryCount>0,
Whats SubcategoryCount?Is it a global variable?How you are assigning value for that?
|
|
|
|
|
That is not any Variable...That is just i written...
But I want to Use ddlSubcategories.Items.Count in place of SubCategoryCount..
But I Am not Getting the value...
Actually if user doesnt select category then Select Category alert will Prompt..If User Selected Category And There is no Subcategory of that then we allow him to proceed...But if that category has some Sub Categories then its must to Select SubCategory...
Thats what i Want in Else Condition u see...
|
|
|
|
|
Sachin Dubey wrote: That is not any Variable...That is just i written...
How we know its simply written.
Ok.Try ddlSubCategory.options.length
|
|
|
|
|
Thanks Arun I Got The count By :
if (document.getElementById("<%=ddlSubCategories.ClientID%>").options.length > 1)
Now its showing the message also...But Its Saving the record ...
My Code of Button is:
<asp:button id="btnSave" runat="server" text="Save" width="100px" onclientclick="javascript:validate();" onclick="btnSave_Click">
After reading that script it reading On_click event Code...
How to Tackele that..
|
|
|
|
|
Sachin Dubey wrote: OnClientClick="javascript:validate();"
Instead try this,
OnClientClick="return validate();"
|
|
|
|
|
Hey Arun... It Works...
Thanks A Lot....
|
|
|
|
|
Hi,
I am having datatable .. i want to add columns to that , i need to add same column once again ... is it possible ???
if it possible pls let me know the right path ...
for i=0 to 10
datatable.column.add("values to be added")
next
note: it throughs excepttion like , column already exist
thanks,
sekannak...
kannak
|
|
|
|
|
sekannak wrote: . i want to add columns to that , i need to add same column once again
I don't think that your idea is good.If you are trying to add same column again you'll get that error.What you are trying to acheive by adding same column again?
|
|
|
|
|
As you have found, column names must be unique. The values you store in the column can be the same of course.
only two letters away from being an asset
|
|
|
|
|
hi
i have created a ASP.NET web application.
I have 3 web forms (.aspx) pages in that.I have 2 hyperlinks in one page.when i click on that link,the repective page should load.I am able to display page from link(without frames),but link disappears(since it's another page).
So can anybody tell me how to create frames,so that page will be displayed in some area and hyperlink will be visible at top?
"Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"
|
|
|
|
|
You can use Master & Content page for this functionality.
Keep hyperlinks in MasterPage and add other 2 pages as content page.
|
|
|
|
|
You don't have to do anything special. Just create a page that contains frames, and put your page in one, and your static page in the other.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|