Solved

Datagrid html output without <table> tags

Posted on 2004-10-26
330 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
Question by:Summit-IT
    11 Comments
     
    LVL 28

    Expert Comment

    by:mmarinov
    Hi Summit-IT,

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

    Regards!
    B..M
    0
     

    Author Comment

    by:Summit-IT
    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
    I don't think you can sorry;(

    Aeros
    0
     
    LVL 17

    Expert Comment

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

    Author Comment

    by:Summit-IT
    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
    no there isn't
    0
     
    LVL 9

    Expert Comment

    by:riyasjef
    Try this

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

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

    RJ
    0
     
    LVL 9

    Accepted Solution

    by:
    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
    isn't that just goint to add an extra table tag before and after???
    0
     
    LVL 3

    Expert Comment

    by:nitrogenx
    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
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    846 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now