【问题标题】:Values wont pass- only the null, and update values in the grid值不会传递 - 只传递空值,并更新网格中的值
【发布时间】:2018-08-30 12:42:17
【问题描述】:

以下是我的C#代码和aspx代码。此代码假设更新页面上的网格,但是当我单击保存时,它不会传递在评论框中输入的值并更新。

protected void btnSaveComments_Click(object sender, EventArgs e)
{
    if (txtRowIndex.Value != string.Empty)
    {
     int gridViewRowIndex = Convert.ToInt32(txtRowIndex.Value);
     txtFlaggedComments.Text = txtFlaggedComments.Text.Replace("'", "`");
     gvSalesmanLicenseList.Rows[gridViewRowIndex].Cells[14].Text = trimComment(txtFlaggedComments.Text, 15);
     gvSalesmanLicenseList.Rows[gridViewRowIndex].Cells[14].ToolTip = txtFlaggedComments.Text; 
     gvSalesmanLicenseList.Rows[gridViewRowIndex].Cells[18].Text = txtFlaggedComments.Text;
     gvSalesmanLicenseList.Rows[gridViewRowIndex].Cells[14].ToolTip.Replace("'", "''");

     LinkButton lblEditComments = (LinkButton)gvSalesmanLicenseList.Rows[gridViewRowIndex].FindControl("lbEditComments");

     lblEditComments.Attributes.Add("onclick", "ShowMyModalPopup('" + gvSalesmanLicenseList.Rows[gridViewRowIndex].RowIndex + "','" + txtFlaggedComments.Text + "')");

     UpdatePanel1.Update();

    }

}

还有 HTML:

<td style="vertical-align: middle; width: 154px; height: 22px; text-align: right" 
    valign="middle" align="right">
    <asp:Button ID="btnPrintSalesmanContinue"OnClick="btnPrintSalesmanContinue_Click"
        runat="server" Text="Submit" __designer:wfdid="w110" CausesValidation="false" 
        UseSubmitBehavior="False></asp:Button>
</td>

【问题讨论】:

    标签: c# asp.net webforms


    【解决方案1】:

    我相信您需要访问单元格的(第一个)控件并将其转换为所需的 WebControl。我假设是 TextBox 或 Label。

         ((TextBox)gvSalesmanLicenseList.Rows[gridViewRowIndex].Cells[14].Controls[0])).Text = trimComment(txtFlaggedComments.Text, 15);
         ((TextBox)gvSalesmanLicenseList.Rows[gridViewRowIndex].Cells[14].Controls[0])).ToolTip = txtFlaggedComments.Text; 
         ((TextBox)gvSalesmanLicenseList.Rows[gridViewRowIndex].Cells[18].Controls[0])).Text = txtFlaggedComments.Text;
         ((TextBox)gvSalesmanLicenseList.Rows[gridViewRowIndex].Cells[14].Controls[0])).ToolTip.Replace("'", "''");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-18
      • 2014-09-14
      • 2012-04-30
      • 2021-02-19
      • 1970-01-01
      相关资源
      最近更新 更多