社区
分析与设计
帖子详情
Girdview控件怎么使用
bihai621
2009-04-10 10:19:35
VS中的Girdview控件怎么使用?
...全文
96
7
打赏
收藏
Girdview控件怎么使用
VS中的Girdview控件怎么使用?
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
7 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
数据之巅
2012-03-19
打赏
举报
回复
你想怎么用,最简单的就是数据绑定,数据显示啊,然后一些其他功能要靠自己慢慢摸索啊,自己想什么功能,不会的去看帮助,网上搜一下啊。。。
九度空间
2012-03-14
打赏
举报
回复
grid控件:(DataGridView)
获取与设置grid的行列及单元格的数据集合:
xx.Columns;
xx.Rows;
xx.Rows[行索引].Cells;
设置行列数及标题行列数:
xx.RowCount;
xx.ColumnCount;
插入,删除行和列:
xx.Rows.Add(行数); //末尾插入一个新行
xx.Rows.Insert(索引,行数); //插入一个新行
xx.Rows.RemoveAt(索引); //删除一行
xx.Columns.Add(列ID字符串,列标题); //末尾插入一个新列
xx.Columns.RemoveAt(索引); //删除一列
设置与获取文本:
xx.Rows[行索引].Cells[列索引].Value;
设置与获取某列的标题:
xx.Columns[索引].HeaderText;
设置行高及列宽:
xx.Rows[索引].Height;
xx.Columns[索引].Width;
xx.RowTemplate.Height; //设置所有行的行高
设置最左侧固定列的宽度:
xx.RowHeadersWidth;
设置只读状态:
xx.ReadOnly = true;
允许拖动列:
xx.AllowUserToOrderColumns = true;
隐藏最左侧固定列:
xx.RowHeadersVisible = false;
冻结某行或某列:
xx.Rows[索引].Frozen = true;
xx.Columns[索引].Frozen = true;
设置表格线条颜色:
xx.GridColor = SystemColors..;
设置奇数行的颜色:
xx.AlternatingRowsDefaultCellStyle.BackColor = SystemColors..;
设置表格空缺部分的背景色:
xx.BackgroundColor = SystemColors..;
设置滚动条:
xx.ScrollBars = ScrollBars..;
lujunql
2012-03-01
打赏
举报
回复
GridView无代码分页排序:
1.AllowSorting设为True,aspx代码中是AllowSorting="True";
2.默认1页10条,如果要修改每页条数,修改PageSize即可,在aspx代码中是PageSize="12"。
3.默认的是单向排序的,右击GridView弹出“属性”,选择AllowSorting为True即可。
GridView选中,编辑,取消,删除:
后台代码:
你可以使用sqlhelper,本文没用。代码如下:
1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Web;
5 using System.Web.Security;
6 using System.Web.UI;
7 using System.Web.UI.WebControls;
8 using System.Web.UI.WebControls.WebParts;
9 using System.Web.UI.HtmlControls;
10 using System.Data.SqlClient;
11
12 public partial class _Default : System.Web.UI.Page
13 {
14 //清清月儿http://blog.csdn.net/21aspnet
15 SqlConnection sqlcon;
16 SqlCommand sqlcom;
17 string strCon = "Data Source=(local);Database=数据库名;Uid=帐号;Pwd=密码";
18 protected void Page_Load(object sender, EventArgs e)
19 {
20 if (!IsPostBack)
21 {
22 bind();
23 }
24 }
25 protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
26 {
27 GridView1.EditIndex = e.NewEditIndex;
28 bind();
29 }
30
31 //删除
32 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
33 {
34 string sqlstr = "delete from 表 where id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
35 sqlcon = new SqlConnection(strCon);
36 sqlcom = new SqlCommand(sqlstr,sqlcon);
37 sqlcon.Open();
38 sqlcom.ExecuteNonQuery();
39 sqlcon.Close();
40 bind();
41 }
42
43 //更新
44 protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
45 {
46 sqlcon = new SqlConnection(strCon);
47 string sqlstr = "update 表 set 字段1='"
48 + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "',字段2='"
49 + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim() + "',字段3='"
50 + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + "' where id='"
51 + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
52 sqlcom=new SqlCommand(sqlstr,sqlcon);
53 sqlcon.Open();
54 sqlcom.ExecuteNonQuery();
55 sqlcon.Close();
56 GridView1.EditIndex = -1;
57 bind();
58 }
59
60 //取消
61 protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
62 {
63 GridView1.EditIndex = -1;
64 bind();
65 }
66
67 //绑定
68 public void bind()
69 {
70 string sqlstr = "select * from 表";
71 sqlcon = new SqlConnection(strCon);
72 SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
73 DataSet myds = new DataSet();
74 sqlcon.Open();
75 myda.Fill(myds, "表");
76 GridView1.DataSource = myds;
77 GridView1.DataKeyNames = new string[] { "id" };//主键
78 GridView1.DataBind();
79 sqlcon.Close();
80 }
81 }
82
83
前台主要代码:
1 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
2 ForeColor="#333333" GridLines="None" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing"
3 OnRowUpdating="GridView1_RowUpdating" OnRowCancelingEdit="GridView1_RowCancelingEdit">
4 <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
5 <Columns>
6 <asp:BoundField DataField="身份证号码" HeaderText="用户ID" ReadOnly="True" />
7 <asp:BoundField DataField="姓名" HeaderText="用户姓名" />
8 <asp:BoundField DataField="员工性别" HeaderText="性别" />
9 <asp:BoundField DataField="家庭住址" HeaderText="家庭住址" />
10 <asp:CommandField HeaderText="选择" ShowSelectButton="True" />
11 <asp:CommandField HeaderText="编辑" ShowEditButton="True" />
12 <asp:CommandField HeaderText="删除" ShowDeleteButton="True" />
13 </Columns>
14 <RowStyle ForeColor="#000066" />
15 <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
16 <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
17 <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
18 </asp:GridView>
19
Lugyedo
2012-03-01
打赏
举报
回复
Repeater空间比较好,轻量级的GridView
xuancheng999
2009-04-10
打赏
举报
回复
Girdview.DataSource=Iist; //绑定
Girdview.DataBind(); //显示
knifewei
2009-04-10
打赏
举报
回复
http://hi.baidu.com/xfm_zhr/blog/item/36fd86125b5b53cac2fd78fd.html
asp.net中GridView
控件
的强大技术点集合
asp.net的GridView
控件
的技术
使用
asp.net的GridView
控件
的技术
使用
asp.net的GridView
控件
的技术
使用
asp.net的GridView
控件
的技术
使用
(本人保证绝对实用经典整合!!!)
GridView
控件
应用十个经典实例
4、GridView
控件
中DropDownList
控件
的绑定 5、GridView
控件
中动态添加模板列 6、通过CheckBox删除选中记录 7、在GridView
控件
中实现跨页面多选 8、删除GridView
控件
行信息弹出确认提示框 9、在GridView
控件
中实现在...
android 通过GridView
控件
获取本地图片并动态显示 程序源码
文章是参考博客http://blog.csdn.net/eastmount/article/details/41808179完成,主要讲述通过GridView
控件
点击加号图片动态添加本地相册图片,点击图片可以删除已添加图片。同时界面比较美观。 免费资源,希望对大家...
GridView固定表头和列 实例(GridView冻结表头和列)
在ASP.NET开发中,GridView
控件
是用于展示数据表格的常用工具,尤其在处理大量数据时,它提供了灵活的配置和样式化选项。本实例主要关注如何实现GridView的固定表头和列,使得用户在滚动浏览长表格时,表头和部分列...
android Gridview分页实现
在Android开发中,GridView是一种常用的布局
控件
,它允许我们以网格的形式展示数据。当我们处理大量数据时,分页加载可以提高应用性能,减少内存消耗,并提供更好的用户体验。本篇文章将详细讲解如何在Android中利用...
分析与设计
13,189
社区成员
5,759
社区内容
发帖
与我相关
我的任务
分析与设计
.NET技术 分析与设计
复制链接
扫一扫
分享
社区描述
.NET技术 分析与设计
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章