努力的小菜鸡~ 2016-05-14 08:06 采纳率: 0%
浏览 1362

gridview控件点击“处理/取消”显示索引超出范围,各位大神帮忙看看,感激不尽!!!

我的数据库表qianfei 的id字段为自编,对欠费审核时,点击“处理/取消”显示索引超出范围,各位大神帮忙看看,感激不尽!!!
cs代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class 欠费审核 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.aa();
}
public void aa()
{
SqlConnection con = BD.createDB();
con.Open();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter sda = new SqlDataAdapter("select * from qianfei ", con);
DataSet ds = new DataSet();
sda.Fill(ds, "qianfei");
this.gvqf.DataSource = ds;
this.gvqf.DataBind();
con.Close();
}
protected void gvqf_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onMouseOver", "Color=this.style.backgroundColor;this.style.backgroundColor='lightBlue'");
e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor=Color;");
if (e.Row.Cells[7].Text == "已缴费")
{
e.Row.Cells[7].Text = "已缴费";
}
else
{
e.Row.Cells[7].Text = "未缴费";
}
}
}
protected void gvqf_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
_ string id = this.gvqf.DataKeys[e.NewSelectedIndex].Value.ToString();_
SqlConnection con = BD.createDB();
con.Open();
SqlCommand cmd = new SqlCommand("select state from qianfei where id='" + id + "'", con);

    string count = cmd.ExecuteScalar().ToString();
    if (count == "已缴费")
    {
        count = "未缴纳";
    }
    else
    {
        count = "已缴费";
    }
    cmd.CommandText = "update tousu set state='" + count + "'where id='" + id + "'";
    cmd.ExecuteNonQuery();
    con.Close();
    this.aa();
}
protected void gvqf_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    gvqf.PageIndex = e.NewPageIndex;
    this.aa();
}

}

我想上传调式图片,上传不了啊

  • 写回答

2条回答 默认 最新

  • threenewbee 2016-05-15 00:06
    关注

    e.NewSelectedIndex
    ->
    e.RowIndex

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败