Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access the cell content of a pure html table from asp.net

Tags:

jquery

c#

asp.net

I have a table:

<table id="trTable" runat="server" clientidmode="Static">
        <thead>
            <tr>
                <th style="display:none">
                    ID
                </th>
                <th style="width: 112px">
                    Item
                </th>
                <th style="width: 40px; text-align: left">
                    Price
                </th>
                <th style="width: 24px; text-align: center">
                </th>
                <th style="width: 26px; text-align: center">
                    Qty
                </th>
                <th style="width: 24px; text-align: center">
                </th>
                <th style="width: 40px; text-align: right">
                    Total
                </th>
            </tr>
        </thead>
        <tbody>
        </tbody>
    </table>

and new rows are added to it with jQuery:

var newRow = $("<tr> <td class='drinkID' style='display:none'>" + drinkID + "</td> <td class='drinkName'>" + dName + "</td>  <td class='drinkPrice'>" + dPrice + "</td>  <td style='text-align:center'><input id='Button' type='button' value='<' class='minusButton' /> </td>  <td class='drinkQty'>1</td>  <td style='text-align:center'><input id='Button' type='button' value='>' class=\"plusButton\" /></td>  <td class='drinkTotal'>" + dPrice + "</td>  </tr>");

How do I access the content of the cells using asp.net?

I am using:

foreach (HtmlTableRow row in trTable.Rows)
        {
            Response.Write("RowDetails:" + row.Cells[1].InnerHtml);
        }

But the response.write just outputs:

RowDetails: Item

How come it doesn't get the cell contents?

like image 299
Ben Avatar asked Jan 23 '26 13:01

Ben


1 Answers

What you change on the html struct page, on client side, is not send back on the server, and sever know nothing about.

With other words, what is on the page, is not fully sanded back on the server.

To solve this, you can make at the same time two edits, one on what user see and one hidden on a hidden input, to post back to the server the changes and recreate the table on the server side.

Hope this make scene.

like image 142
Aristos Avatar answered Jan 25 '26 03:01

Aristos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!