开发者

Counting Rows in C# after dynamically adding them with jQuery

I just have a simple ASP Table seen here:

<asp:Table ID="tblCategories" runat="server" CssClass="oneColTable padded-table dataTable">
  开发者_如何转开发  <asp:TableHeaderRow CssClass="tableHeader">
        <asp:TableHeaderCell>Category Name</asp:TableHeaderCell>
        <asp:TableHeaderCell Width="50">Delete</asp:TableHeaderCell>
    </asp:TableHeaderRow>
</asp:Table>

And if the user wants to add an additional row I use the jQuery Clone method to copy and append a new row.

My issue comes when I want to count the rows present on the C# side it always lists 1 Row. The row for the header entry.

How can I correctly grab the accurate row count on the C# (Codebehind) side?

Thanks,

-Seth


When your form submits you have to be able to see some values in the submitted fields to indicate the number of rows. An html form does not just send back all the html from the client to the server. The simplest way to do this would be to add a hidden input field into a cell and in the postback you will be able to see those values and count them. So you will end up cloning that hidden form field when you clone the rows on the client, and that will give you a value in Request["HiddenField"] for example.


yes use the hidden control to recored the row's count of the table.


Im not sure about how to do this in C# but you could create a hidden field that stores the number of rows and use something like $('#hiddenField').val($('#tblCategories > tbody > tr').length). And then get the value of this hidden field in the C# code

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜