日期:2014-05-18  浏览次数:20803 次

救命,急急争,快点帮帮我,一个关于GridView的问题!~
CS代码如下: 
 private void databindtoRP() 
  { 
  string i = "1"; 
  SqlConnection con = DB.crateCon(); 
  con.Open(); 
  SqlDataAdapter sda = new SqlDataAdapter("select top 6 * from NewsTable where N_classid= '" + i + " ' and N_ddid < > '0 ' order by N_id desc", con); 
  DataSet ds = new DataSet(); 
  sda.Fill(ds, "News"); 
   

  this.GridView1.DataSource = ds.Tables["News"]; 
  this.GridView1.DataBind(); 
  } 
HTml:代码如下 

<asp:GridView ID="GridView1" runat="server" Style="position: static" AutoGenerateColumns="False" BorderWidth="0px" Font-Size="10pt" ShowHeader="False" Width="200px" > 
  <Columns > 
  <asp:HyperLinkField DataNavigateUrlFields="N_id" DataNavigateUrlFormatString="showDetails?id={0}" 
  DataTextField="N_content" / > 
  </Columns > 
  <RowStyle BorderWidth="0px" Height="17px" / > 
</asp:GridView > 

我绑定的一个content字段因为数据太多,我想把它像"你好你好你好你好你好你好......."这类显示怎么做呢/ 
小弟在这里先谢了! 
请给个详细的做法,最好能给个示便什么的,小弟先在这里谢过了!

------解决方案--------------------

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound" >
<Columns>
<asp:BoundField DataField="hello1" />
<asp:BoundField DataField="hello2" />
</Columns>
</asp:GridView>
---------------------------------
DB:
DataTable dt = new DataTable();
dt.Columns.Add("hello1");
dt.Columns.Add("hello2");
DataRow dr = dt.NewRow();
dr[0] = "你好你好你好你好你好你好你好你好你好";
dr[1] = "你好你好你好你好你好你好你好你好你好";
dt.Rows.Add(dr);
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
---------------

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.Cells[0].Text.Length > 12)
{ e.Row.Cells[0].Text = e.Row.Cells[0].Text.Substring(0, 12) + "..."; }
}