0

我有一个gridview object用于绑定到datasource. 如果selectedIndexChanging发生gridview,我想将 中显示的数据gridview带入textboxes表格中。但是,当数据包含诸如 &'"" 之类的字母数字字符时,每当我输入字母数字字符时,网格中的数据就会显示 ;amp、#S 等以及所有其他奇怪的字符。textboxes有没有办法防止这些字符在从网格中获取数据时弹出?我到目前为止的代码:

protected void grdActions_SelectedIndexChanged(对象发送者,EventArgs e){

            int selectedRow1 = grdActions.SelectedRow.RowIndex;
            hdnIndexNo.Value = grdActions.Rows[selectedRow1].Cells[1].Text;
            ddlActionType.SelectedValue = grdActions.Rows[selectedRow1].Cells[3].Text;


            if (grdActions.Rows[selectedRow1].Cells[4].Text == null || grdActions.Rows[selectedRow1].Cells[4].Text == string.Empty || grdActions.Rows[selectedRow1].Cells[4].Text == " ")
            {
                txtDetails.Text = string.Empty;
            }
            else
            {
                txtDetails.Text = grdActions.Rows[selectedRow1].Cells[4].Text;
            }

            if (grdActions.Rows[selectedRow1].Cells[5].Text == null || grdActions.Rows[selectedRow1].Cells[5].Text == string.Empty || grdActions.Rows[selectedRow1].Cells[5].Text == " ")
            {
                txtCompletedDate.Text = string.Empty;
            }
            else
            {
                txtCompletedDate.Text = Convert.ToDateTime(grdActions.Rows[selectedRow1].Cells[5].Text).ToString("dd-MMM-yyyy");
            }

            ddlActionOwner.SelectedValue = grdActions.Rows[selectedRow1].Cells[7].Text;

            if (grdActions.Rows[selectedRow1].Cells[8].Text == null || grdActions.Rows[selectedRow1].Cells[8].Text == string.Empty || grdActions.Rows[selectedRow1].Cells[8].Text == " ")
            {
                txtAssignedTo.Text = string.Empty;
            }
            else
            {
                txtAssignedTo.Text = grdActions.Rows[selectedRow1].Cells[8].Text;
            }


            if (grdActions.Rows[selectedRow1].Cells[9].Text == null || grdActions.Rows[selectedRow1].Cells[9].Text == string.Empty || grdActions.Rows[selectedRow1].Cells[9].Text == " ")
            {
                lblComments.Visible = false;
                txtComments.Visible = false;
            }
            else
            {
                lblComments.Visible = true;
                txtComments.Visible = true;
                txtComments.Text = grdActions.Rows[selectedRow1].Cells[9].Text;
            }
4

1 回答 1

0

在将数据从网格视图传输到文本框时,我使用了 Server.HTMLDecode()。这确保在将所有特殊字符发送回表单上的文本框之前将其删除

于 2013-02-05T15:46:07.290 回答