前台GridView属性设置
<td>
<asp:GridView ID="GridView" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox runat="server" />
</ItemTemplate>
<HeaderTemplate>
<asp:CheckBox runat="server"/>
</HeaderTemplate>
</asp:TemplateField>
<asp:BoundField DataField="cusername" HeaderText="名字" />
<asp:BoundField DataField="cusercode" HeaderText="ID" />
<asp:BoundField DataField="cpwddate" HeaderText="SEX" />
<asp:BoundField DataField="ccreateusername" HeaderText="Memo" />
<asp:TemplateField>
<ItemTemplate>
<a href="javascript:MyTest(‘<%#Eval("cusercode")!=""?Eval("cusercode").ToString():"" %>‘)">修改</a>
</ItemTemplate>
<HeaderTemplate>
操作
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<a href="javascript:MyTest(‘<%#Eval("cusercode")!=""?Eval("cusercode").ToString():"" %>‘)">查看</a>
</ItemTemplate>
<HeaderTemplate>
查看
</HeaderTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
后台数据绑定:
因为连接的是Oracle数据库,所以需要导入命名空间
using System.Data;
using System.Data.OracleClient;
string Conn = "server=mrm;uid=bcc;pwd=bcc.51";
OracleConnection Cconn = new OracleConnection(Conn);
OracleDataAdapter Da = new OracleDataAdapter("select * from T_user",Cconn);
DataSet ds = new DataSet();
Da.Fill(ds);
this.GridView.DataSource = ds.Tables[0].DefaultView;
this.GridView.DataBind();
显示的效果(比较粗糙):