Wednesday, January 28, 2009
Create Excel from Dataset.
Code:
gridView1.DataSource = dsEmployee.tables(0)
Me.gridView1.DataBind()
' Set the content type to Excel.
Response.ContentType = "application/vnd.ms-excel"
' Remove the charset from the Content-Type header.
Response.Charset = ""
' Turn off the view state.
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
' Get the HTML for the control.
'DataGrid1.RenderControl(hw)
'Render the grid.
gridView1.RenderControl(hw)
' Write the HTML back to the browser.
Response.Write(tw.ToString())
' End the response.
Response.End()
By above code you can export the data to excel.
But some time when we render the grid we face problem like :
"Control 'gridView1' of type 'GridView' must be placed inside a form tag with runat=server"
Add following code in you page :
Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
' Confirms that an HtmlForm control is rendered for the
' specified ASP.NET server control at run time.
' No code required here.
End Sub
That code solve my problem. Hope same for you Guys.
Sunday, January 25, 2009
Use AJAX with check box in Gridview to avoid postback.
How we can use? Wait i am coming with source code.
Saturday, January 24, 2009
Convert DataGrid to GridView.
I am coming with very intresting topic. Currently i am working on conversion project. I am converting dotnet1.1 project to dot net 3.5. Microsoft provide the tool to convert the application. But it is not converting Datagrid to GridView. So i am doing manually. So here i am discussion some point to consider when we convert grids.
Currently i am writing down only the steps and very soon i will publish the code also. till you can ask th ecode via email id : tomksaini@gmail.com
Changes on .aspx file
1. In Datagrid we have tag "TemplateColumn", but in GridView we have "TemplateField". So when convert the datagrid to Gridview, take care ot these things. We need to change manually
Example :
DataGrid :
2. In DataGrid we have tag "ItemStyle" , but in GridView we have "RowStyle"
Example :
DataGrid :
It depends how many functionality you have implemented with grid. I am covering most common here,
1. ItemDataBound /RowDataBound:
In datagrid, "ItemDataBound" fire when we bind the grid. corresponding to this , we have "RowDataBound" event in Gridview.
For example "
DataGrid :
MyDataGrid_ItemDataBound(ByVal Sender As Object, ByVal E As DataGridItemEventArgs)
GridView :
MyGridNew_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles MyGridNew.RowDataBound
In Datagrid, we have many item type and accordingly we use them. while converting just replace
following
e.Item.ItemType = ListItemType.EditItem
E.Item.ItemType = ListItemType.AlternatingItem
with
e.Row.RowType = DataControlRowType.DataRow.
(EditItem, AlternatingItem not supported by GridView)
2. ItemCreated/RowCreated:
In datagrid, "ItemCreated" fire when item created in grid. corresponding to this , we have "RowCreated" event in Gridview.
For Example:
Datagrid :
Sub MyDataGrid_ItemCreated(ByVal Sender As Object, ByVal e As DataGridItemEventArgs)
GridView :
Sub MyGridNew_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles MyGridNew.RowCreated
* need to take care of "editItem" and "AlternatingItem"
3. Update/RowUpdating :
In DataGrid, we have we have one update event which one fire when updation happen. In Gridview we have we event : one is "Updating" and another one is "Updated".
(a) Updating : just before the actual updation and we can also cancel the updation at that time also.
(b) Updated: just after the updation happen.
So replace DataGrid's Update event with GridView's Updating.
4. CurrentPageIndex/PageIndex:
In datagrid we have one property "CurrentPageIndex" but in gridView we have "PageIndex" property to set/get the page index.
I have covered most common event and changes. I hope it will help you. You can contact me tomksaini@gmail.com .
Convert dot net 1.1 to dot net 3.5
Hi friends,
After a long time, I am posting new article. In this article we discuss how to migrate dot net 1.1 web application into dot net 3.5.
Follow the following steps for migration.
Step 1. Open M S studio 2008 and go to open project.
Step 2. Brows your existing project location.
Step 3. Now MS Studio will start the conversion....it will ask you for backup. Just for safer side click the "yes" button. And click on next button. Conversion is started.
Step 4. Conversion is finished.
Step 5. Just go to project folder and open the solution file (.sln) in note pad. Now it is showing MS Studio 2008 and version 10.0.0.
Step 6. In solution window, right click your project and select "Web Conversion" option.
Step 7. Go to properties of your project. in setting check the "Targer Framework" showing 3.5.
Now your application successfuly converted to dot net 3.5....... :)
But there is a problem. Your DataGrid is not converted to GridView. MS studio 2008 provides backward compatiability for DataGrid. So to convert datagrid in to gridview is manually process...........
I have converted datagrid to gridview and now i am working on conversion too......In next article you will get the conversion process for datagrid to gridview......... and very tool i will come with automatic tool for conversion.........