zoukankan
html css js c++ java
GridView删除,编辑应用
using
TestWeb.HR.BusinessLogicLayer;
using
TestWeb.HR.DataAccessLayer;
public
partial
class
HR_CompanyView : System.Web.UI.UserControl
...
{
protected
void
Page_Load(
object
sender, EventArgs e)
...
{
if
(
!
this
.IsPostBack)
...
{
GetAllCompanies();
//
初试加载所有公司
}
}
/**/
///
<summary>
///
返回所有公司
///
</summary>
private
void
GetAllCompanies()
...
{
try
...
{
List
<
Company
>
companyList
=
new
List
<
Company
>
();
companyList
=
Company.GetAllCompanies();
if
(companyList
!=
null
)
...
{
this
.GridView1.DataSource
=
companyList;
this
.GridView1.DataBind();
}
}
catch
(Exception ex)
...
{
ShowMessage.ErrorMessage(
this
.Page, ex.Message);
}
}
/**/
///
<summary>
///
编辑公司
///
</summary>
///
<param name="sender"></param>
///
<param name="e"></param>
protected
void
GridView1_RowEditing(
object
sender, GridViewEditEventArgs e)
...
{
this
.GridView1.EditIndex
=
e.NewEditIndex;
GetAllCompanies();
}
/**/
///
<summary>
///
取消编辑
///
</summary>
///
<param name="sender"></param>
///
<param name="e"></param>
protected
void
GridView1_RowCancelingEdit(
object
sender, GridViewCancelEditEventArgs e)
...
{
this
.GridView1.EditIndex
=
-
1
;
GetAllCompanies();
}
/**/
///
<summary>
///
更新公司
///
</summary>
///
<param name="sender"></param>
///
<param name="e"></param>
protected
void
GridView1_RowUpdating(
object
sender, GridViewUpdateEventArgs e)
...
{
GridViewRow uprow
=
this
.GridView1.Rows[e.RowIndex];
TextBox text1
=
(TextBox)uprow.Cells[
0
].FindControl(
"
TextBox1
"
);
TextBox text2
=
(TextBox)uprow.Cells[
0
].FindControl(
"
TextBox2
"
);
TextBox text3
=
(TextBox)uprow.Cells[
0
].FindControl(
"
TextBox3
"
);
HyperLink hlk
=
(HyperLink)uprow.Cells[
0
].FindControl(
"
HyperLink1
"
);
int
companyId
=
Convert.ToInt32(
this
.GridView1.DataKeys[e.RowIndex].Value);
//
直接调用存储过程进行更新
string
connectionstring
=
ConfigurationManager.ConnectionStrings[
"
TESTDB_Database_Connection
"
].ConnectionString;
SqlCommand upcmd
=
new
SqlCommand();
upcmd.CommandType
=
CommandType.StoredProcedure;
upcmd.CommandText
=
"
UPCompany
"
;
upcmd.Parameters.Add(
"
@CompanyName
"
, SqlDbType.VarChar,
50
);
upcmd.Parameters[
"
@CompanyName
"
].Value
=
text1.Text.Trim();
upcmd.Parameters.Add(
"
@Phone
"
, SqlDbType.VarChar,
50
);
upcmd.Parameters[
"
@Phone
"
].Value
=
text2.Text.Trim();
upcmd.Parameters.Add(
"
@Fax
"
, SqlDbType.VarChar,
50
);
upcmd.Parameters[
"
@Fax
"
].Value
=
text3.Text.Trim();
upcmd.Parameters.Add(
"
@WebSite
"
, SqlDbType.VarChar,
50
);
upcmd.Parameters[
"
@WebSite
"
].Value
=
hlk.Text.Trim();
upcmd.Parameters.Add(
"
@CompanyId
"
, SqlDbType.Int,
4
);
upcmd.Parameters[
"
@CompanyId
"
].Value
=
companyId;
SqlConnection con
=
new
SqlConnection(connectionstring);
upcmd.Connection
=
con;
con.Open();
upcmd.ExecuteNonQuery();
con.Close();
this
.GridView1.EditIndex
=
-
1
;
GetAllCompanies();
}
/**/
///
<summary>
///
删除公司
///
</summary>
///
<param name="sender"></param>
///
<param name="e"></param>
protected
void
GridView1_RowDeleting(
object
sender, GridViewDeleteEventArgs e)
...
{
int
companyId
=
Convert.ToInt32(
this
.GridView1.DataKeys[e.RowIndex].Value);
string
connectionstring
=
ConfigurationManager.ConnectionStrings[
"
TESTDB_Database_Connection
"
].ConnectionString;
SqlCommand delcmd
=
new
SqlCommand();
delcmd.CommandType
=
CommandType.StoredProcedure;
delcmd.CommandText
=
"
HR_DeleteCompanyByCompanyId
"
;
delcmd.Parameters.Add(
"
@CompanyId
"
, SqlDbType.Int,
4
);
delcmd.Parameters[
"
@CompanyId
"
].Value
=
companyId;
SqlConnection _Con
=
new
SqlConnection(connectionstring);
delcmd.Connection
=
_Con;
_Con.Open();
delcmd.ExecuteNonQuery();
_Con.Close();
GetAllCompanies();
}
/**/
///
<summary>
///
允许分页
///
</summary>
///
<param name="sender"></param>
///
<param name="e"></param>
protected
void
GridView1_PageIndexChanging(
object
sender, GridViewPageEventArgs e)
...
{
this
.GridView1.PageIndex
=
e.NewPageIndex;
GetAllCompanies();
}
/**/
///
<summary>
///
焦点行颜色变化
///
</summary>
///
<param name="sender"></param>
///
<param name="e"></param>
protected
void
GridView1_RowDataBound(
object
sender, GridViewRowEventArgs e)
...
{
if
(e.Row.RowType
==
DataControlRowType.DataRow)
...
{
//
当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色
e.Row.Attributes.Add(
"
onmouseover
"
,
"
currentcolor=this.style.backgroundColor;this.style.backgroundColor='yellow',this.style.fontWeight='';
"
);
//
当鼠标离开的时候 将背景颜色还原的以前的颜色
e.Row.Attributes.Add(
"
onmouseout
"
,
"
this.style.backgroundColor=currentcolor,this.style.fontWeight='';
"
);
}
//
单击行改变行背景颜色
if
(e.Row.RowType
==
DataControlRowType.DataRow)
...
{
e.Row.Attributes.Add(
"
onclick
"
,
"
this.style.backgroundColor='#99cc00'; this.style.color='buttontext';this.style.cursor='default';
"
);
}
}
/**/
///
<summary>
///
根据ID获取公司详细信息
///
</summary>
///
<param name="sender"></param>
///
<param name="e"></param>
protected
void
Button1_Click(
object
sender, EventArgs e)
...
{
Response.Redirect(
"
~/CompanyDetails.aspx
"
);
}
}
查看全文
相关阅读:
The provided URI scheme 'http' is invalid; expected 'https'. Parameter name: via
WCF传递Stream时,同时传递其它参数的问题
DotNet NB 学习公众号
军师旅团营连排班各有多少人
OAuth 2.0学习
人生三境界
Mac OS安装Windows各版本时注意事项(2014年后的Mac机相信会有这些问题)
C#中winform使用相对路径读取文件的方法
Sql Server Report Service 的部署问题(Reporting Service 2014為什麼不需要IIS就可以運行)
Reporting Services报表常用的URL参数
原文地址:https://www.cnblogs.com/scgw/p/1094902.html
最新文章
接口和抽象类的区别
idea之jrebel热部署使用教程
Log4j配置概述
Tomcat原理的一点看法
动态规划
蚂蚁金服数据质量治理架构与实践
蚂蚁区块链BaaS平台架构与实践
人工智能在财富领域的应用与探索
实时智能决策引擎在蚂蚁金服风险管理中的实践
蚂蚁金服分布式链路跟踪组件 SOFATracer 总览 | 剖析
热门文章
Java11 & JavaFX 初体验
蚂蚁金服分布式链路跟踪组件 SOFATracer 数据上报机制和源码分析 | 剖析
java内存管理机制剖析(一)
最佳实践 | OceanBase事务引擎的技术创新
Java8实用技能
draw.io
ajax异步提交修改按钮文字
关闭页面前js提示
window.open关闭后刷新父页面
abp vNex
Copyright © 2011-2022 走看看