C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Interview   Jobs   Projects   Offshore Development    
Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing | Talk to Us |



My Profile

Gifts

Active Members
TodayLast 7 Days more...







datagrid clearcontrols (VB) Export to excel or CSv


Posted Date: 12 Aug 2004      Total Responses: 2

Posted By: gujju       Member Level: Silver     Points: 2


hi..

i have a datagrid.. which i currently export to excel and csv according to what user wants... now i just had paging in my datagrid and the same code is giving me error of not declaring the datagrid in runat=server...

i did googled for some time and found that its happening due to the paging control of the datagrid. i also got some code to clear controls in C# and i really dont know C#

i have got the code which i got it from csharpcorner... so can any one help me with the code in vb???

here is the C# code.

private void ClearControls(Control control)
{
for (int i=control.Controls.Count -1; i>=0; i--)
{
ClearControls(control.Controls[i]);
}

if (!(control is TableCell))
{
if (control.GetType().GetProperty("SelectedItem") != null)
{
LiteralControl literal = new LiteralControl();
control.Parent.Controls.Add(literal);
try
{
literal.Text = (string)control.GetType().GetProperty("SelectedItem").GetValue(control,null);
}
catch

{

}

control.Parent.Controls.Remove(control);
}

else

if (control.GetType().GetProperty("Text") != null)
{
LiteralControl literal = new LiteralControl();
control.Parent.Controls.Add(literal);
literal.Text = (string)control.GetType().GetProperty("Text").GetValue(control,null);
control.Parent.Controls.Remove(control);
}
}
return;
}

Does n one knows to convert it to VB

Any Help would be Much apprieciated

Cheers
Chintan




Responses

Author: gujju    12 Aug 2004Member Level: SilverRating:     Points: 2
Got the Function....

here it is...if some one wants it.. Just steal it man.... :)



Imports System.Web.UI

Public Sub ClearControls(ByVal control As Control)
'This function is used to Clear all the controls in the datagrid
'Will Clear all the ServerControls Which are in the Datagrid
'Such as edit command, paging, checkboxes in datagrid and all
'the server controls
'it will replace the server control with simple text for that control
'Where Can this be Used:
'Exporting Datagrid and Clearing Datagrid
Dim i As Integer
For i = control.Controls.Count - 1 To 0 Step -1
ClearControls(control.Controls(i))
Next i

If Not TypeOf control Is System.Web.UI.WebControls.TableCell Then
If Not (control.GetType().GetProperty("SelectedItem") Is Nothing) Then
Dim literal As New LiteralControl
control.Parent.Controls.Add(literal)
Try
literal.Text = CStr(control.GetType().GetProperty("SelectedItem").GetValue(control, Nothing))
Catch
End Try
control.Parent.Controls.Remove(control)
Else
If Not (control.GetType().GetProperty("Text") Is Nothing) Then
Dim literal As New LiteralControl
control.Parent.Controls.Add(literal)
literal.Text = CStr(control.GetType().GetProperty("Text").GetValue(control, Nothing))
control.Parent.Controls.Remove(control)
End If
End If
End If
Return
End Sub 'ClearControls


Author: MuthuKumar    12 Aug 2004Member Level: BronzeRating:     Points: 2
Hi
pls look this link you can get better idia about this


http://www.dotnetjohn.com/articles/articleid78.aspx

bye
Muthu Kumar


Post Reply
You must Sign In to post a response.
Previous : Validation Controls
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

audio conferencing services

Contact Us    Privacy Policy    Terms Of Use