0
我有一個gridview
object
我正在使用綁定到datasource
。在gridview
的selectedIndexChanging
事件中,我想將gridview
中顯示的數據帶入表單中的textboxes
。但是,如果數據包含字母數字字符(如&'「」),則每當輸入字母數字字符時,網格中的數據都會顯示; amp,#S等以及所有其他奇怪的字符。從網格中獲取數據時,有沒有辦法阻止這些字符在textboxes
中彈出? 我有迄今爲止的代碼:從gridview數據中刪除特殊字符
保護無效grdActions_SelectedIndexChanged(對象發件人,EventArgs的) {
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;
}
請發佈您迄今爲止所嘗試的內容......並且我的意思是代碼。 – Brian
不要拒絕特殊字符。相反,您需要修復代碼,以便它們正確顯示。請告訴我們你的代碼。 – SLaks
字母數字字符實際上是字符,表示字母,如a或b或數字。您的特殊字符&'「」不是字母數字。 – Nolonar