Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在回发时保留动态内容_C#_Javascript_Jquery_.net_Postback - Fatal编程技术网

C# 在回发时保留动态内容

C# 在回发时保留动态内容,c#,javascript,jquery,.net,postback,C#,Javascript,Jquery,.net,Postback,我有一个默认情况下如下所示的表: <table width="650" id="myTable" runat="server"> <tbody> <tr> <td class="cellWidth300 bottomBorder topBorder">Column1</td> <td class="cellWidth125 leftBorder topBord

我有一个默认情况下如下所示的表:

<table width="650" id="myTable" runat="server">
    <tbody>
        <tr>
            <td class="cellWidth300 bottomBorder topBorder">Column1</td>
            <td class="cellWidth125 leftBorder topBorder bottomBorder textCenter">Column2</td>
            <td class="cellWidth100 leftBorder topBorder bottomBorder textCenter">Column3</td>
            <td class="cellWidth125 leftBorder rightBorder topBorder bottomBorder textRight">Column4</td>
        </tr>
        <tr>
            <td class="cellWidth300"><input type="text" size="29" runat="server"/></td>
            <td class="cellWidth125 leftBorder textCenter"><input type="text" size="9" class="units commas" runat="server"/></td>
            <td class="cellWidth100 leftBorder textCenter"><input type="text" size="8" class="value commas" runat="server"/></td>
            <td class="cellWidth125 leftBorder rightBorder textRight"><input type="text" size="11" readonly="readonly" tabindex="-1" class="totalA1 autoTotal" runat="server"/>&nbsp;</td>
        </tr>
        <tr>
            <td class="cellWidth300"><input id="Text2" type="text" size="29" runat="server"/></td>
            <td class="cellWidth125 leftBorder textCenter"><inputtype="text" size="9" class="units commas" runat="server"/></td>
            <td class="cellWidth100 leftBorder textCenter"><input  type="text" size="8" class="value commas" runat="server"/></td>
            <td class="cellWidth125 leftBorder rightBorder textRight"><input type="text" size="11" readonly="readonly" tabindex="-1" class="totalA1 autoTotal" runat="server"/>&nbsp;</td>
        </tr>
        <tr>
            <td class="cellWidth300"><input  type="text" size="29" runat="server"/></td>
            <td class="cellWidth125 leftBorder textCenter"><input type="text" size="9" class="units commas" runat="server"/></td>
            <td class="cellWidth100 leftBorder textCenter"><input type="text" size="8" class="value commas" runat="server"/></td>
            <td class="cellWidth125 leftBorder rightBorder textRight"><input type="text" size="11" readonly="readonly" tabindex="-1" class="totalA1 autoTotal" runat="server" />&nbsp;</td>
        </tr>
    </tbody>
</table>
var _addRow ='<tr>' +
'<td width="300"><input type="text" size="29" runat="server" ></td>' +
'<td width="125" class="leftBorder textCenter"><input type="text" size="9" class="units commas" runat="server" /></td>' +
'<td width="100" class="leftBorder textCenter"><input type="text" size="8" class="value commas" runat="server" /></td>' +
'<td width="125" class="leftBorder rightBorder textRight"><input type="text" size="11" readonly="readonly" tabindex="-1" class="totalA1 autoTotal" runat="server" />&nbsp;</td>' +
'</tr>';

function initialize() {
$(document).on('keypress', '#myTable tr:last input', AddRowToMyTable);
}

function AddRowToMyTable() {
$('#myTable tr:last').after(_addRow);
}
private void WriteMyTableToXML()
{
    HtmlInputText tContent;
    HtmlTableRow tRow;

    int i = 1; //First row is headers, which we don't want.

    _Writer.WriteStartElement("MyTable");

    while (i < tblCropsAndFeed.Rows.Count - 1) // last row should always be blank.  We can skip it
    {
        tRow = tblCropsAndFeed.Rows[i];

        _Writer.WriteStartElement("Entry");

        string tInputBox0 = tRow.Cells[0].Controls[0].ClientID;
        tContent = (HtmlInputText)tRow.FindControl(tInputBox0);
        _Writer.WriteStartElement("name");
        _Writer.WriteString(tContent.Value);
        _Writer.WriteEndElement();

        string tInputBox1 = tRow.Cells[1].Controls[0].ClientID;
        tContent = (HtmlInputText)tRow.FindControl(tInputBox1);
        _Writer.WriteStartElement("units");
        _Writer.WriteString(tContent.Value);
        _Writer.WriteEndElement();

        string tInputBox2 = tRow.Cells[2].Controls[0].ClientID;
        tContent = (HtmlInputText)tRow.FindControl(tInputBox2);
        _Writer.WriteStartElement("value");
        _Writer.WriteString(tContent.Value);
        _Writer.WriteEndElement();

        _Writer.WriteEndElement();

        i++;
    }

    _Writer.WriteEndElement();
}

因此,我认为最好的选择是使用带有服务器端绑定的ASP GridView。当您编辑或向gridview添加行时,它将在回发时使用您从创建的XML文件提供的数据自动重建

您是否加载任何初始数据,或者它只是没有绑定的纯html和.NET控件?它只是没有绑定的纯html和.NET控件。您是否每次都写入同一个xml文件?正如您一直在覆盖或附加数据一样?该程序允许您命名数据,因此用户可以选择创建新数据或覆盖现有数据。您以前使用过gridview控件吗?在代码隐藏中使用绑定?
If(IsPostBack)
    {
    DontResetThePage();
    }