关于GridView的onrowdatabound方法中多次连接数据库很快会造成连接满的情况

sd722522 2012-05-08 06:06:49
如题,GridView的onrowdatabound方法中多次连接数据库很快会造成连接满的情况,进而造成满查询,或者执行sql存储过程失败,导致程序不能正常运行
各位csdn高手们有没有什么方法可以防止这种情况??
或者说有没有什么方法可以像onrowdatabound一样改变GridView中的状态

付源码

protected void gv_Task_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow gvr = e.Row;
if (gvr.RowIndex >= 0)
{
String TaskId = gvr.Cells[0].Text;
gvr.Cells[5].Text = GetIsUseTestNumberString(gvr.Cells[5].Text);
gvr.Cells[6].Text = GetIsUseTestNumberString(gvr.Cells[6].Text);
HyperLink SF = (HyperLink)e.Row.Cells[9].Controls[0];
SF.ToolTip = "群发任务发送的省份";
Button btnStop = gvr.FindControl("btnStop") as Button;
ImageButton ibtnDelete = gvr.FindControl("ibtnDelete") as ImageButton;

if (!ChackTime(gvr.Cells[0].Text))
{
HyperLink hlf = (HyperLink)e.Row.Cells[10].Controls[0];
hlf.NavigateUrl = "SgsTaskTimeList.aspx?TaskId=" + TaskId + "";
hlf.Text = "未赋时段";
hlf.Font.Bold = true;
hlf.ToolTip = "未赋时段任务无法开始发送";
//hlf.BackColor = System.Drawing.Color.Red;//背景
//hlf.BorderColor = System.Drawing.Color.Blue;//边框
hlf.ForeColor = System.Drawing.Color.Red;//文字

}
else
{
HyperLink hl = (HyperLink)e.Row.Cells[10].Controls[0];
hl.ToolTip = "任务在时段内才发送";

}


switch (gvr.Cells[7].Text)
{
//case "1":
// HyperLink ZT = (HyperLink)e.Row.Cells[7].Controls[0];
// break;
case "3":
btnStop.Text = "重新启动";
btnStop.ToolTip = "重启该短信群发任务";
btnStop.OnClientClick = "return confirm('确定重新启动该短信群发任务吗?')";
break;
case "2":
ibtnDelete.Enabled = false;
btnStop.Enabled = false;
break;
case "4":
ibtnDelete.Enabled = false;
btnStop.Enabled = false;
break;
default:
break;
}
gvr.Cells[7].Text = GetTaskStatusString(gvr.Cells[7].Text);
//这段调用数据库的代码总是导致问题出现sql已经不能优化了
if (gvr.Cells[7].Text.Equals("执行中"))
{
if (SgsWebBll.CheckAllProvinceTask(Int32.Parse(gvr.Cells[0].Text)) == 0)
{
gvr.Cells[7].Text = "暂停中";
gvr.Cells[7].ForeColor = System.Drawing.Color.Red;
}
}
}



...全文
186 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
sd722522 2012-05-10
  • 打赏
  • 举报
回复
自己顶。。
怎么。。这区没人呢?
sd722522 2012-05-09
  • 打赏
  • 举报
回复
别沉啊,来人啊,求帮助啊

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧