gridview 的问题
数据源是手写的,我想对字段进行操作,比如 我表中的字段名是age 我想显示成 “年龄” 还有把字段b 都显示成超连接,请问如何操作
public partial class test : System.Web.UI.Page
{
public static DataTable ds(string que)
{
string strConnection = "Provider=Microsoft.Jet.OleDb.4.0; ";
strConnection += @ "Data Source=e:\db.mdb ";
OleDbConnection connect = new OleDbConnection(strConnection);
OleDbDataAdapter oda = new OleDbDataAdapter();
oda.SelectCommand = new OleDbCommand(que, connect);
DataSet ds = new DataSet();
oda.Fill(ds, "a ");
return ds.Tables[ "a "];
}
protected void Page_Load(object sender, EventArgs e)
{
GridView1.DataSource = ds( "select * from [d] ");
GridView1.DataBind();
}
}
------解决方案--------------------超连接用个模版列:
<asp:TemplateFieldHeaderText= "名 "> <ItemTemplate>
<script type= "text/javascript ">
<!--
document.write( " <a href=\ "xxxx.aspx?id= <%# DataBinder.Eval (Container.DataItem, "字段 ")%> \ "> <%# DataBinder.Eval(Container.DataItem, "字段 ")%> </a> ")
-->
</script>
</ItemTemplate>
</asp:TemplateField>
------解决方案--------------------关于age...
处理一下SQL语句
select age as '年龄 ',字段,字段 from D
------解决方案--------------------GridView里添加列时,最后一项就是模版列