简体   繁体   中英

c# - Click on link to create a table?

Hmmm not sure how to exactly ask this.

What i want to do is to be able to click on a link called surname and then below i want a table generated with a list of everyone with that surname from the database.

<input type="text" id="surname" name="surname" size="10" /><a href="javascript:surname();">Surname</a> 
        <input type="text" id="forename" name="forename" size="10" /><a href="javascript:forename();">Forename</a> 

        <table id = "t" visible="false" runat="server">
        <tr>
            <th>Surname</th>
            <th>Forename</th>
            <th>D.O.B</th>
        </tr>
        </table>

To get the data the quesry select * from surname will return surname, forname and dob

This is roughly what i have at the moment. I know i have to call a function somwhere and then return something to generate the data in side the table 't' but how?

Not sure if im getting what you want, but i convert datatables to html tables thus. Hope it helps.

public string WriteResult(DataTable dt)
{

    DataGrid dg = new DataGrid();
    dg.CellPadding = 5;
    dg.BackColor = System.Drawing.Color.White;
    dg.BorderColor = System.Drawing.Color.Gray;
    dg.Font.Name = "Arial";
    dg.Font.Size = FontUnit.XSmall;
    dg.HeaderStyle.Font.Bold = true;
    dg.FooterStyle.Font.Bold = true;

    dg.DataSource = dt;
    dg.DataBind();

    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);

    dg.RenderControl(hw);

    return sw.ToString();

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM