Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Datagrid html output without <table> tags

Posted on 2004-10-26
11
Medium Priority
?
376 Views
Last Modified: 2011-10-03
I need the html ouput from our custom datagrid to start with a <tr> instead of a <table>.  The output will be placed inside of a surrounding table.  How can I strip the <table> tags off the top and bottom of the datagrid output?  
0
Comment
Question by:Summit-IT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 28

Expert Comment

by:mmarinov
ID: 12414590
Hi Summit-IT,

just use a repeater control
you can define what should be rendered

Regards!
B..M
0
 

Author Comment

by:Summit-IT
ID: 12414700
We can't use a repeater control because we have a custom datagrid that has all of our feautures already built in.  We have to make it work with the datagrid control.  Any suggestions?
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12414722
I don't think you can sorry;(

Aeros
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:AerosSaga
ID: 12414747
could you not just insert the whole <table> inside a <tr>??
0
 

Author Comment

by:Summit-IT
ID: 12414799
I know it sounds crazy not to just put it inside of <tr> but thats not an option for us.  Is there maybe away to just render the table rows and table cells from the datagrid without the <table> tag?  Thanks
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12414817
no there isn't
0
 
LVL 9

Expert Comment

by:riyasjef
ID: 12414822
Try this

<table>
<tr>
<td width="100%">
<asp:dataGrid
.......
......
/>

</td>
</tr>
</table>

RJ
0
 
LVL 9

Accepted Solution

by:
riyasjef earned 1500 total points
ID: 12415227
Or something like this

System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

DataGrid dg=new DataGrid;
...................
....................
dg.RenderControl(oHtmlTextWriter);
String strCode=oStringWriter.ToString();

// strip <table> from  strCode using RegExp

Response.Write("<table>");
Response.Write(strCode);
Response.Write("</table>");

RJ
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12415236
isn't that just goint to add an extra table tag before and after???
0
 
LVL 3

Expert Comment

by:nitrogenx
ID: 12417408
NOTE: Partial points to riyasjef if this works

aspx:
    //Your table tag
    <asp:DataGrid Runat=Server ID=DataGrid1 Visible=false></asp:DataGrid>
    <asp:Label Runat=Server ID=DataGridRender></asp:Label>
    //Your end table tag

codebehind:
        System.Text.StringBuilder stringBuilder1 = new System.Text.StringBuilder();
        System.Web.UI.HtmlTextWriter htmlTextWriter1 =
            new System.Web.UI.HtmlTextWriter(
                new System.IO.StringWriter(stringBuilder1));
        DataGrid1.Visible = true;
        DataGrid1.RenderControl(htmlTextWriter1);
        DataGrid1.Visible = false;
        string text = stringBuilder1.ToString();
        int start = text.IndexOf('>') + 1;
        int end = text.LastIndexOf('<');
        if (start < end && start != -1 && end != -1)
            DataGridRender.Text = text.Substring(start,end-start);

This works because the table tag should never contain a premature > and the </table> tag should never have a premature < I am 99.9% sure that there is no situation you will be working with that will put a > somewhere in the table tag, but be forewarned.
0
 

Author Comment

by:Summit-IT
ID: 12422330
I ended up making it work by rendering the control from start to finish using:

protected override void Render(HtmlTextWriter writer)


I accepted riyasjef 's answer because he gave me the idea to start with the HTMLTextWriter.

I wanted to give partial points to nitrogenx but I couldn't find the partial points option.  My mistake.

Thanks.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question