简体   繁体   English

从gridview数据中删除特殊字符

[英]Removing special characters from gridview data

I have a gridview object that I am using to bind to a datasource . 我有一个用来绑定到datasourcegridview object Upon the selectedIndexChanging event of the gridview , I would like to bring the data shown in the gridview into the textboxes on the form. 一旦selectedIndexChanging的事件gridview ,我想提请在显示的数据gridviewtextboxes的形式。 However, when the data contains alphanumeric characters such as &'"", the data from the grid is showing ;amp, #S etc. and all other weird characters whenever I enter an alphanumeric character. 但是,当数据包含字母数字字符(例如&'“”)时,每当我输入字母数字字符时,来自网格的数据就会显示; amp,#S等以及所有其他奇怪的字符。 Is there a way to prevent these characters from popping up in the textboxes when taking data from the grid? 从网格获取数据时,是否有办法防止这些字符在textboxes弹出? The code that I have so far: 到目前为止,我拥有的代码:

protected void grdActions_SelectedIndexChanged(object sender, EventArgs e) { 受保护的void grdActions_SelectedIndexChanged(object sender,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;
            }

I used the Server.HTMLDecode() when transferring the data fromthe gridview to the textboxes. 在将数据从gridview传输到文本框时,我使用了Server.HTMLDecode()。 This ensured that all special characters were removed before it was sent back to the textboxes on the form 这样可以确保在将所有特殊字符发送回表单上的文本框之前将其删除

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM