菜鸟问题:用什么控件来显示数据库查询的2列1-5行结果? 本帖最后由 ETJojo 于 2014-11-07 19:06:12 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以这样简单显示:var dg = new GridView { DataSource = 查询数据库返回多条数据() };Form.Controls.Add(dg);dg.DataBind(); 自我感觉winform查询不用datagrid,可以用listview,listbox之类的查询前五行的话是在select语句中写,比如select TOP 5 *from 表名 这句话就是查询这个中的前五行 GridView控件显示数据查询的两列1~5行结果//GridView设置 <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" CellPadding="4" Font-Size="9pt" ForeColor="#333333" GridLines="None" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDataBound="GridView1_RowDataBound" OnRowDeleting="GridView1_RowDeleting" Width="500px"> <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /> <RowStyle BackColor="#E3EAEB" /> <Columns>//codego.net/tags/11/1/ <asp:BoundField DataField="ST_l_name" HeaderText="网站名称" /> <asp:BoundField DataField="ST_l_url" HeaderText="链接网址" /> <asp:HyperLinkField DataNavigateUrlFields="ST_l_id" DataNavigateUrlFormatString="AmendLink.aspx?ID={0}" </Columns> <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#7C6F57" /> <AlternatingRowStyle BackColor="White" /> </asp:GridView>//加载绑定数据显示两列-1~5行数据 protected void Page_Load(object sender, EventArgs e) { /*判断是否登录*/ ST_check_Login(); SqlData da = new SqlData(); //调用公共类中的ExceDS方法执行SQL语句 this.GridView1.DataSource = da.ExceDS("select top 5 * from ST_news order by ST_Trme desc");//按时间顺序降序显示前5条数据 GridView1.DataKeyNames = new string[] { "id" }; GridView1.DataBind();//绑定数据 } 你愿意放到table里也可放一堆textbox里,甚至一堆label,这又没人强求关键是看怎么样看起来舒服,怎么样做起来简单罢了另外考虑一下以后是否数据会变化,比如目前是10行,以后如果变成300行,是否要分页之类的 谢谢楼上各位,看来还是用datgrid的好 我的代码有问题了 .net做统计图用了OpenFlashChart如何更改X轴上的刻度为时间呢 formview silentwins 您的回答不得不补分啊 自定义DropDownList 救我一命,胜造十级浮屠!救命啊!!! datalist问题 Map Network Drive (API)的疑问? “找不到用来与FrontPage服务器扩展通信的组件”是什么意思? 在.net中如何实现push技术(asp中的remote scripting) repeater控件中的image绑定多个图片能实现吗? 有什么情况可能导致网站客户端失去响应呢(非JS)
Form.Controls.Add(dg);
dg.DataBind();
//GridView设置
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
CellPadding="4" Font-Size="9pt" ForeColor="#333333" GridLines="None" OnPageIndexChanging="GridView1_PageIndexChanging"
OnRowDataBound="GridView1_RowDataBound" OnRowDeleting="GridView1_RowDeleting"
Width="500px">
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#E3EAEB" />
<Columns>//codego.net/tags/11/1/
<asp:BoundField DataField="ST_l_name" HeaderText="网站名称" />
<asp:BoundField DataField="ST_l_url" HeaderText="链接网址" />
<asp:HyperLinkField DataNavigateUrlFields="ST_l_id" DataNavigateUrlFormatString="AmendLink.aspx?ID={0}"
</Columns>
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#7C6F57" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
//加载绑定数据显示两列-1~5行数据
protected void Page_Load(object sender, EventArgs e)
{
/*判断是否登录*/
ST_check_Login();
SqlData da = new SqlData();
//调用公共类中的ExceDS方法执行SQL语句
this.GridView1.DataSource = da.ExceDS("select top 5 * from ST_news order by ST_Trme desc");//按时间顺序降序显示前5条数据
GridView1.DataKeyNames = new string[] { "id" };
GridView1.DataBind();//绑定数据
}
放一堆textbox里,甚至一堆label,这又没人强求
关键是看怎么样看起来舒服,怎么样做起来简单罢了
另外考虑一下以后是否数据会变化,比如目前是10行,以后如果变成300行,是否要分页之类的