ASP.NET2.0中用Gridview控件操作数据的代码
更新时间:2021年9月22日 10:18 点击:2006
其中,在数据控件方面,增加了不少控件,其中的Gridview控件功能十分强大。在本文中,将探讨Gridview控件中的一些功能特性和用法,如果各位读者对Gridview控件不大了解,可以通过《使用ASP.NET 2.0中的Gridview控件》一文,来对Gridview控件有个初步的认识。
1、使用Gridview插入新记录
在Gridview控件中,可以实现插入新记录的操作(见《使用ASP.NET 2.0中的Gridview控件》)一文,但如果想实现在Gridview中,实现在Gridview控件的最后一行,提供一个空白行给用户输入要输入的记录,那无疑是很方便的。下面将介绍其实现方法。
首先,我们打算在让用户进行选择,当用户需要新增一记录时,便点击新增按钮,之后在Gridview的最后一行里,显示一个空白行,让用户按字段进行输入,如下图所示:
当用户决定不输入新空白记录时,可以按"cancel"按钮返回,该空白行消失。要实现这样的效果,我们可以充分利用Gridview的footer的模版功能进行自定义,因为有3列,所以,在每一列的footer模版中,定义如下:
<asp:Gridview ID="Gridview1" Runat="server" DataSourceID="SqlDataSource1" DataKeyNames="CustomerID" AutoGenerateColumns="False" ShowFooter="True">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="CustomerIDLabel" Runat="Server"><%# Eval("CustomerID") %></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="CustomerIDTextBox" Runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="CompanyNameLabel" Runat="Server"><%# Eval("CompanyName") %></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="CompanyNameTextBox" Runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<FooterTemplate>
<asp:DropDownList ID="ContactTitleDropDownList" Runat="server" DataSourceID="SqlDataSource2" DataTextField="ContactTitle" DataValueField="ContactTitle">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" Runat="server" SelectCommand="SELECT DISTINCT [ContactTitle] FROM [Customers]"
ConnectionString="server=localhost;uid=sa;password=xxx;database=northwind">
</asp:SqlDataSource>
<asp:Button ID="Button1" Runat="server" Text="Add" OnClick="Button1_Click" />
<asp:Button ID="CancelButton1" Runat="server" Text="Cancel" OnClick="CancelButton1_Click" />
</FooterTemplate>
<ItemTemplate>
<asp:DropDownList ID="ContactTitleDropDown" SelectedValue='<%# Bind("ContactTitle") %>' Runat="Server" DataSourceID="SqlDataSource3" DataTextField="ContactTitle" DataValueField="ContactTitle" ></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" Runat="server" SelectCommand="SELECT DISTINCT [ContactTitle] FROM [Customers]"
ConnectionString="server=localhost;uid=sa;password=xxxx;database=northwind" EnableCaching="True">
</asp:SqlDataSource>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:Gridview>
以上为Gridview的代码,可以看到,在第一,二列的<foottemplate>列中,分别提供了customerid和companyname两个文本框以供用户输入,在第三列的<footertemplate>列中,以dropdownlistbox的形式来显示contracttitle.。其中,请注意第三列的footertemplate中的add和cancel两个按钮的,它们的事件代码如下
<script runat="server">
void CancelButton1_Click(object sender, EventArgs e)
{
Gridview1.ShowFooter = false;
}
void AddButton1_Click(object sender, EventArgs e)
{
Gridview1.ShowFooter = true;
}
//点add按钮时,将新增的记录更新到数据库中去
void Button1_Click(object sender, EventArgs e)
{
TextBox customerID = Gridview1.FooterRow.FindControl("CustomerIDTextBox") as TextBox;
TextBox companyName = Gridview1.FooterRow.FindControl("CompanyNameTextBox") as TextBox;
DropDownList ContactTitle = Gridview1.FooterRow.FindControl("ContactTitleDropDownList") as DropDownList;
SqlDataSource1.InsertParameters["CustomerID"].DefaultValue = customerID.Text;
SqlDataSource1.InsertParameters["CompanyName"].DefaultValue = companyName.Text;
SqlDataSource1.InsertParameters["ContactTitle"].DefaultValue=ContactTitle.SelectedValue;
SqlDataSource1.Insert();
}
</script>
其中的cancel按钮的事件,用来取消显示Gridview的footer模版,因此设置showfooter属性为false,而addbutton1按钮,是当用户决定新增记录时点选的,此时将设置showfooter属性为true,以显示各列的foottemplate,从而达到显示新的一个空白行的目的。
而在更新代码button1_click事件中,将首先使用Gridview1.footerrow.findcontrol的方法,将用户新增的各字段的值提取出来,然后分别赋值给sqldatasource的insertparameters集合(注意要一一对应),最后使用sqldatasource的insert方法,就可以成功向数据库增加一条新记录了。
另外,为了在窗体加载时,显示数据库northwind中customers表的数据,需要设置sqldatsource1的属性,如下代码:
<asp:SqlDataSource ID="SqlDataSource1" Runat="server"
InsertCommand="INSERT INTO [Customers] ([CustomerID], [CompanyName], [ContactTitle]) VALUES (@CustomerID, @CompanyName, @ContactTitle)"
SelectCommand="SELECT top 5 [CustomerID], [CompanyName], [ContactTitle] FROM [Customers]"
ConnectionString="server=localhost;uid=sa;password=XXXXX;database=northwind">
<InsertParameters>
<asp:Parameter Type="String" Name="CustomerID"></asp:Parameter>
<asp:Parameter Type="String" Name="CompanyName"></asp:Parameter>
<asp:Parameter Type="String" Name="ContactTitle"></asp:Parameter>
</InsertParameters>
</asp:SqlDataSource>
其中,必须设置insertcommand和selectcommand属性,设置数据提取和插入的语句,并且要设置好insertparameters集合中,各字段的类型和名称即可。
2、一次性更新所有的Gridview记录
我们经常会遇到这样的情况,在Gridview中列出的所有记录中,有时要同时修改多条记录,并且将其保存到数据库中去。那么在Gridview中应该如何实现呢?在Gridview中,有两种实现的方法,下面分别进行介绍:
先来看下第一种方法,本方法是使用sqldatasource来更新所有记录,但这个方法比较慢,因为每更新一条记录都要建立数据连接并执行updatecommand,会影响性能。其主要代码如下:
<script runat="server">
void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < Gridview1.Rows.Count; i++)
{
GridviewRow row = Gridview1.Rows[i];
SqlDataSource1.UpdateParameters[0].DefaultValue = ((TextBox)row.Cells[0].FindControl("TextBox2")).Text;
SqlDataSource1.UpdateParameters[1].DefaultValue = ((TextBox)row.Cells[1].FindControl("TextBox3")).Text;
SqlDataSource1.UpdateParameters[2].DefaultValue = Gridview1.DataKeys[i].Value.ToString();
SqlDataSource1.Update();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Gridview ID="Gridview1" Runat="server" DataSourceID="SqlDataSource1" DataKeyNames="CustomerID" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField SortExpression="CustomerID" HeaderText="CustomerID">
<ItemTemplate>
<asp:TextBox Runat="server" Text='<%# Bind("CustomerID") %>' ID="TextBox1"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="CompanyName" HeaderText="CompanyName">
<ItemTemplate>
<asp:TextBox Runat="server" Text='<%# Bind("CompanyName") %>' ID="TextBox2"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="ContactName" HeaderText="ContactTitle">
<ItemTemplate>
<asp:TextBox Runat="server" Text='<%# Bind("ContactTitle") %>' ID="TextBox3"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:Gridview>
<asp:SqlDataSource ID="SqlDataSource1" Runat="server"
SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName], [ContactTitle] FROM [Customers]"
UpdateCommand="UPDATE [Customers] SET [CompanyName] = @CompanyName, [ContactTitle] = @ContactTitle WHERE [CustomerID] = @CustomerID"
ConnectionString="server=localhost;uid=sa;password=xxxx;database=northwind">
<UpdateParameters>
<asp:Parameter Type="String" Name="CompanyName"></asp:Parameter>
<asp:Parameter Type="String" Name="ContactTitle"></asp:Parameter>
<asp:Parameter Type="String" Name="CustomerID"></asp:Parameter>
</UpdateParameters>
</asp:SqlDataSource>
<asp:Button ID="Button1" Runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>
在上面的代码中,我们必须首先指定updateparameters参数集合,也就是指出要更新的是哪些字段,它们的类型是什么。之后并指出sqldatasource的updatecommand语句。而在更新按钮button1的CLICK事件中,将以遍历的形式,使用for循环,对Gridview中的每一行进行检查,将每个更新了的文本框的内容放到sqldatasouce的updateparameters参数中去,最后调用sqldatasource的update方法,完成更新。
方法2使用的是首先遍历Gridview中的每一行,并且使用SQL语句,将要更新的内容连接起来,然后最后才使用command.ExecuteNonQuery()进行更新,效率高了,主要代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString1"].ConnectionString);
SqlCommand command = new SqlCommand("SELECT [CustomerID], [CompanyName], [ContactName], [ContactTitle] FROM [Customers]", con);
con.Open();
Gridview1.DataSource = command.ExecuteReader();
Gridview1.DataBind();
con.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
StringBuilder query = new StringBuilder();
for (int i = 0; i < Gridview1.Rows.Count; i++)
{
GridviewRow row = Gridview1.Rows[i];
string value1 = ((TextBox)row.Cells[0].FindControl("TextBox2")).Text.Replace("'", "''");
string value2 = ((TextBox)row.Cells[1].FindControl("TextBox3")).Text.Replace("'", "''");
string value3 = Gridview1.DataKeys[i].Value.ToString();
query.Append("UPDATE [Customers] SET [CompanyName] = '").Append(value1).Append("' , [ContactTitle] = '")
.Append(value2).Append("' WHERE [CustomerID] = '").Append(value3).Append("';\n");
}
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString1"].ConnectionString);
SqlCommand command = new SqlCommand(query.ToString(), con);
con.Open();
command.ExecuteNonQuery();
con.Close();
}
}
其中要特别注意一点的是,在vs.net 2005 beta 2开始,如果你在web.config中使用了数据库连接字符串的配置,那么应该按如下的方法去写:
<connectionStrings>
<add name="NorthwindConnectionString" connectionString="Data Source=LIAO;Initial Catalog=Northwind;User ID=sa;Password=xxxx" providerName="System.Data.SqlClient"/>
</connectionStrings>
然后在程序中如下进行读取:
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString1"].ConnectionString);
1、使用Gridview插入新记录
在Gridview控件中,可以实现插入新记录的操作(见《使用ASP.NET 2.0中的Gridview控件》)一文,但如果想实现在Gridview中,实现在Gridview控件的最后一行,提供一个空白行给用户输入要输入的记录,那无疑是很方便的。下面将介绍其实现方法。
首先,我们打算在让用户进行选择,当用户需要新增一记录时,便点击新增按钮,之后在Gridview的最后一行里,显示一个空白行,让用户按字段进行输入,如下图所示:
当用户决定不输入新空白记录时,可以按"cancel"按钮返回,该空白行消失。要实现这样的效果,我们可以充分利用Gridview的footer的模版功能进行自定义,因为有3列,所以,在每一列的footer模版中,定义如下:
复制代码 代码如下:
<asp:Gridview ID="Gridview1" Runat="server" DataSourceID="SqlDataSource1" DataKeyNames="CustomerID" AutoGenerateColumns="False" ShowFooter="True">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="CustomerIDLabel" Runat="Server"><%# Eval("CustomerID") %></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="CustomerIDTextBox" Runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="CompanyNameLabel" Runat="Server"><%# Eval("CompanyName") %></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="CompanyNameTextBox" Runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<FooterTemplate>
<asp:DropDownList ID="ContactTitleDropDownList" Runat="server" DataSourceID="SqlDataSource2" DataTextField="ContactTitle" DataValueField="ContactTitle">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" Runat="server" SelectCommand="SELECT DISTINCT [ContactTitle] FROM [Customers]"
ConnectionString="server=localhost;uid=sa;password=xxx;database=northwind">
</asp:SqlDataSource>
<asp:Button ID="Button1" Runat="server" Text="Add" OnClick="Button1_Click" />
<asp:Button ID="CancelButton1" Runat="server" Text="Cancel" OnClick="CancelButton1_Click" />
</FooterTemplate>
<ItemTemplate>
<asp:DropDownList ID="ContactTitleDropDown" SelectedValue='<%# Bind("ContactTitle") %>' Runat="Server" DataSourceID="SqlDataSource3" DataTextField="ContactTitle" DataValueField="ContactTitle" ></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" Runat="server" SelectCommand="SELECT DISTINCT [ContactTitle] FROM [Customers]"
ConnectionString="server=localhost;uid=sa;password=xxxx;database=northwind" EnableCaching="True">
</asp:SqlDataSource>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:Gridview>
以上为Gridview的代码,可以看到,在第一,二列的<foottemplate>列中,分别提供了customerid和companyname两个文本框以供用户输入,在第三列的<footertemplate>列中,以dropdownlistbox的形式来显示contracttitle.。其中,请注意第三列的footertemplate中的add和cancel两个按钮的,它们的事件代码如下
复制代码 代码如下:
<script runat="server">
void CancelButton1_Click(object sender, EventArgs e)
{
Gridview1.ShowFooter = false;
}
void AddButton1_Click(object sender, EventArgs e)
{
Gridview1.ShowFooter = true;
}
//点add按钮时,将新增的记录更新到数据库中去
void Button1_Click(object sender, EventArgs e)
{
TextBox customerID = Gridview1.FooterRow.FindControl("CustomerIDTextBox") as TextBox;
TextBox companyName = Gridview1.FooterRow.FindControl("CompanyNameTextBox") as TextBox;
DropDownList ContactTitle = Gridview1.FooterRow.FindControl("ContactTitleDropDownList") as DropDownList;
SqlDataSource1.InsertParameters["CustomerID"].DefaultValue = customerID.Text;
SqlDataSource1.InsertParameters["CompanyName"].DefaultValue = companyName.Text;
SqlDataSource1.InsertParameters["ContactTitle"].DefaultValue=ContactTitle.SelectedValue;
SqlDataSource1.Insert();
}
</script>
其中的cancel按钮的事件,用来取消显示Gridview的footer模版,因此设置showfooter属性为false,而addbutton1按钮,是当用户决定新增记录时点选的,此时将设置showfooter属性为true,以显示各列的foottemplate,从而达到显示新的一个空白行的目的。
而在更新代码button1_click事件中,将首先使用Gridview1.footerrow.findcontrol的方法,将用户新增的各字段的值提取出来,然后分别赋值给sqldatasource的insertparameters集合(注意要一一对应),最后使用sqldatasource的insert方法,就可以成功向数据库增加一条新记录了。
另外,为了在窗体加载时,显示数据库northwind中customers表的数据,需要设置sqldatsource1的属性,如下代码:
复制代码 代码如下:
<asp:SqlDataSource ID="SqlDataSource1" Runat="server"
InsertCommand="INSERT INTO [Customers] ([CustomerID], [CompanyName], [ContactTitle]) VALUES (@CustomerID, @CompanyName, @ContactTitle)"
SelectCommand="SELECT top 5 [CustomerID], [CompanyName], [ContactTitle] FROM [Customers]"
ConnectionString="server=localhost;uid=sa;password=XXXXX;database=northwind">
<InsertParameters>
<asp:Parameter Type="String" Name="CustomerID"></asp:Parameter>
<asp:Parameter Type="String" Name="CompanyName"></asp:Parameter>
<asp:Parameter Type="String" Name="ContactTitle"></asp:Parameter>
</InsertParameters>
</asp:SqlDataSource>
其中,必须设置insertcommand和selectcommand属性,设置数据提取和插入的语句,并且要设置好insertparameters集合中,各字段的类型和名称即可。
2、一次性更新所有的Gridview记录
我们经常会遇到这样的情况,在Gridview中列出的所有记录中,有时要同时修改多条记录,并且将其保存到数据库中去。那么在Gridview中应该如何实现呢?在Gridview中,有两种实现的方法,下面分别进行介绍:
先来看下第一种方法,本方法是使用sqldatasource来更新所有记录,但这个方法比较慢,因为每更新一条记录都要建立数据连接并执行updatecommand,会影响性能。其主要代码如下:
复制代码 代码如下:
<script runat="server">
void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < Gridview1.Rows.Count; i++)
{
GridviewRow row = Gridview1.Rows[i];
SqlDataSource1.UpdateParameters[0].DefaultValue = ((TextBox)row.Cells[0].FindControl("TextBox2")).Text;
SqlDataSource1.UpdateParameters[1].DefaultValue = ((TextBox)row.Cells[1].FindControl("TextBox3")).Text;
SqlDataSource1.UpdateParameters[2].DefaultValue = Gridview1.DataKeys[i].Value.ToString();
SqlDataSource1.Update();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Gridview ID="Gridview1" Runat="server" DataSourceID="SqlDataSource1" DataKeyNames="CustomerID" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField SortExpression="CustomerID" HeaderText="CustomerID">
<ItemTemplate>
<asp:TextBox Runat="server" Text='<%# Bind("CustomerID") %>' ID="TextBox1"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="CompanyName" HeaderText="CompanyName">
<ItemTemplate>
<asp:TextBox Runat="server" Text='<%# Bind("CompanyName") %>' ID="TextBox2"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="ContactName" HeaderText="ContactTitle">
<ItemTemplate>
<asp:TextBox Runat="server" Text='<%# Bind("ContactTitle") %>' ID="TextBox3"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:Gridview>
<asp:SqlDataSource ID="SqlDataSource1" Runat="server"
SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName], [ContactTitle] FROM [Customers]"
UpdateCommand="UPDATE [Customers] SET [CompanyName] = @CompanyName, [ContactTitle] = @ContactTitle WHERE [CustomerID] = @CustomerID"
ConnectionString="server=localhost;uid=sa;password=xxxx;database=northwind">
<UpdateParameters>
<asp:Parameter Type="String" Name="CompanyName"></asp:Parameter>
<asp:Parameter Type="String" Name="ContactTitle"></asp:Parameter>
<asp:Parameter Type="String" Name="CustomerID"></asp:Parameter>
</UpdateParameters>
</asp:SqlDataSource>
<asp:Button ID="Button1" Runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>
在上面的代码中,我们必须首先指定updateparameters参数集合,也就是指出要更新的是哪些字段,它们的类型是什么。之后并指出sqldatasource的updatecommand语句。而在更新按钮button1的CLICK事件中,将以遍历的形式,使用for循环,对Gridview中的每一行进行检查,将每个更新了的文本框的内容放到sqldatasouce的updateparameters参数中去,最后调用sqldatasource的update方法,完成更新。
方法2使用的是首先遍历Gridview中的每一行,并且使用SQL语句,将要更新的内容连接起来,然后最后才使用command.ExecuteNonQuery()进行更新,效率高了,主要代码如下:
复制代码 代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString1"].ConnectionString);
SqlCommand command = new SqlCommand("SELECT [CustomerID], [CompanyName], [ContactName], [ContactTitle] FROM [Customers]", con);
con.Open();
Gridview1.DataSource = command.ExecuteReader();
Gridview1.DataBind();
con.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
StringBuilder query = new StringBuilder();
for (int i = 0; i < Gridview1.Rows.Count; i++)
{
GridviewRow row = Gridview1.Rows[i];
string value1 = ((TextBox)row.Cells[0].FindControl("TextBox2")).Text.Replace("'", "''");
string value2 = ((TextBox)row.Cells[1].FindControl("TextBox3")).Text.Replace("'", "''");
string value3 = Gridview1.DataKeys[i].Value.ToString();
query.Append("UPDATE [Customers] SET [CompanyName] = '").Append(value1).Append("' , [ContactTitle] = '")
.Append(value2).Append("' WHERE [CustomerID] = '").Append(value3).Append("';\n");
}
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString1"].ConnectionString);
SqlCommand command = new SqlCommand(query.ToString(), con);
con.Open();
command.ExecuteNonQuery();
con.Close();
}
}
其中要特别注意一点的是,在vs.net 2005 beta 2开始,如果你在web.config中使用了数据库连接字符串的配置,那么应该按如下的方法去写:
复制代码 代码如下:
<connectionStrings>
<add name="NorthwindConnectionString" connectionString="Data Source=LIAO;Initial Catalog=Northwind;User ID=sa;Password=xxxx" providerName="System.Data.SqlClient"/>
</connectionStrings>
然后在程序中如下进行读取:
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString1"].ConnectionString);
相关文章
- 这篇文章主要介绍了C#实现3步手动建DataGridView的方法,实例分析了C#实现手动创建DataGridView的原理与技巧,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
- 这篇文章主要介绍了C#中DataGridView动态添加行及添加列的方法,涉及C#中DataGridView针对行与列动态操作的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
C#中datagridview使用tooltip控件显示单元格内容的方法
这篇文章主要介绍了C#中datagridview使用tooltip控件显示单元格内容的方法,实例分析了C#控件的相关使用技巧,需要的朋友可以参考下...2020-06-25- 这篇文章主要介绍了C#中GridView动态添加列的实现方法,涉及C#中GridView的相关使用技巧,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
- 下面小编就为大家带来一篇浅析GridView中显示时间日期格式的问题。小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2021-09-22
- 这篇文章主要介绍了C#中DataGridView常用操作,以实例形式总结了DataGridView绑定下拉列表、设置默认值、判断复选框是否选中等技巧,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
- 这个例子的功能是c#读取excel文件,大家可以参考使用...2020-06-25
- Gridview的链接和删除点击提示有利于提醒用户确认下操作是否正确,以免造成不必要的损失,感兴趣的朋友可以参考下,希望对你有所帮助...2021-09-22
- 这篇文章主要介绍了c#中datagridview处理非绑定列的方法,实例分析了C#中datagridview的使用技巧,需要的朋友可以参考下...2020-06-25
实现DataGridView控件中CheckBox列的使用实例
最近做WindowsForms程序,使用DataGridView控件时,加了一列做选择用,发现CheckBox不能选中。搜索后,要实现DataGridView的CellContentClick事件,将代码贴一下...2021-09-22- 这篇文章主要介绍了C#中改变DataGridView控件边框颜色的方法,默认的DataGridView边框颜色很丑,本文用编程方法实现修改DataGridView边框颜色,需要的朋友可以参考下...2020-06-25
- 这篇文章主要介绍了C#中DataGridView的样式设置方法,包括交替行颜色、单元格内容有效性检查、单元格的选择模式等,需要的朋友可以参考下...2020-06-25
在ASP.NET 2.0中操作数据之六十四:GridView批量添加数据
前面介绍了批量更新,批量删除数据,这篇文章主要介绍如何实现批量添加数据,当然为了保证数据的完整性,我们在做这些批量操作的时候,都使用了事务来实现。...2021-09-22.Net语言Smobiler开发利用Gridview控件设计较复杂的表单
这篇文章主要为大家详细介绍了.Net语言Smobiler开发利用Gridview控件设计较复杂的表单,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-09-22- 这篇文章主要是关于GridView使用的学习总结,需要的朋友可以参考下...2021-09-22
DevExpress实现GridView当无数据行时提示消息
这篇文章主要介绍了DevExpress实现GridView当无数据行时提示消息,需要的朋友可以参考下...2020-06-25Asp.net简单代码设置GridView自适应列宽不变形实现思路与代码
动态绑定的GridView由于列数不固定,而列又太多(博主做的这个项目有150个左右的字段),这样设置GridView固定宽度就不能满足需求了...2021-09-22GridView导出Excel常见的5种文本格式 <font color=red>原创</font>
本文主要介绍GridView导出Excel常见的文本格式,以帮助开发人员做导出的Excel时避免出现文本格式不一致的问题。...2021-09-22C# 实现dataGridView选中一行右键出现菜单的示例代码
这篇文章主要介绍了C# 实现dataGridView选中一行右键出现菜单,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-11-03ASP.NET中GridView和Repeater重复数据如何合并
这篇文章主要介绍了ASP.NET中GridView和Repeater重复数据合并的方法,感兴趣的小伙伴们可以参考一下...2021-09-22