虽然我试图将字符串数据绑定到Rad Grid,但它并没有绑定从数据库中提取的确切值。
例如,我拉动数据: - " A BC E F G "并将相同的数据绑定到Rad Grid,这里的问题是rad网格列正在修剪所有空格并显示如下: - " A BC EFG "
这里我需要绑定我从数据库中提取的确切数据。我该怎么做?
答案 0 :(得分:0)
I am unable to replicate out this issue at my end.
My code looks like this:
<强> RadGridPage.aspx 强>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RadgridPage.aspx.cs" Inherits="RadgridPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadGrid ID="TempTable" runat="server" Skin="MetroTouch" PageSize="5">
<MasterTableView CssClass="TempTable" Style="border: 0; cellpadding: 0; cellspacing: 0"
AutoGenerateColumns="false">
<Columns>
<telerik:GridBoundColumn HeaderText="TempData" DataField="TempData">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="TempData" DataField="TempData">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</div>
</form>
</body>
</html>
<强> RadGridPage.aspx.cs 强>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class RadgridPage : System.Web.UI.Page
{
public class data { public string TempData { get; set; } }
protected void Page_Load(object sender, EventArgs e)
{
List<data> gridData = new List<data>()
{
new data(){TempData="A BC E F G"},
new data(){TempData="A BC E F G"},
new data(){TempData="A BC E F G"},
};
TempTable.DataSource = gridData;
}
}
<强> 输出: 强>
答案 1 :(得分:0)
Please update your code to:
<强> RadGridPage.aspx 强>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RadgridPage.aspx.cs" Inherits="RadgridPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadGrid ID="TempTable" runat="server" Skin="MetroTouch" PageSize="5" OnItemDataBound="gvSpecs_ItemDataBound">
<MasterTableView CssClass="TempTable" Style="border: 0; cellpadding: 0; cellspacing: 0"
AutoGenerateColumns="false">
<Columns>
<telerik:GridBoundColumn HeaderText="TempData" UniqueName="TempDataA" DataField="TempData">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="TempData" UniqueName="TempDataB" DataField="TempData">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</div>
</form>
</body>
</html>
<强> RadGridPage.aspx.cs 强>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
public partial class RadgridPage : System.Web.UI.Page
{
public class data { public string TempData { get; set; } }
protected void Page_Load(object sender, EventArgs e)
{
List<data> gridData = new List<data>()
{
new data(){TempData="A BC E F G"},
new data(){TempData="A BC E F G"},
new data(){TempData="A BC E F G"},
};
TempTable.DataSource = gridData;
}
protected void gvSpecs_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
TableCell cellA = (TableCell)item["TempDataA"];
cellA.Text = cellA.Text.Replace(" ", " ");
TableCell cellB = (TableCell)item["TempDataB"];
cellB.Text = cellB.Text.Replace(" ", " ");
}
}
}