| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1549 人关注过本帖
标题:gridview操作数据问题?超紧急
取消只看楼主 加入收藏
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
结帖率:100%
收藏
 问题点数:0 回复次数:3 
gridview操作数据问题?超紧急
//前台主要代码
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" HorizontalAlign="Center" Width="98%" BackColor="White" BorderColor="Blue">
        <Columns>
            <asp:TemplateField HeaderText="选择">
                <ItemTemplate>
                    <asp:CheckBox ID="CheckBox1" runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="UF_OWNERCOMM_NAME" DataFormatString="{0:d}" HeaderText="业主姓名" />
            <asp:BoundField DataField="UF_OWNERCOMM_LOUPAN" DataFormatString="{0:d}" HeaderText="楼盘名称" />
            <asp:BoundField DataField="UF_OWNERCOMM_FLORID" DataFormatString="{0:d}" HeaderText="楼号/名" />
            <asp:BoundField DataField="UF_OWNERCOMM_QQ" DataFormatString="{0:d}" HeaderText="QQ号" />
            <asp:BoundField DataField="UF_OWNERCOMM_Email" DataFormatString="{0:d}" HeaderText="邮箱" />
            <asp:BoundField DataField="UF_OWNERCOMM_PHONE" DataFormatString="{0:d}" HeaderText="电话" />
            <asp:BoundField DataField="UF_OWNERCOMM_CKQX" DataFormatString="{0:d}" HeaderText="查看权限" />
            <asp:BoundField DataField="UF_OWNERCOMM_TXZID" DataFormatString="{0:d}" HeaderText="加入" />
            <asp:BoundField DataField="UF_OWNERCOMM_EXAMINE" DataFormatString="{0:d}" HeaderText="审核状态" />
            <asp:TemplateField HeaderText="操作">
                <ItemTemplate>
                    <asp:Button ID="Button11" runat="server" Text="审批" />
                    <asp:Button ID="Button12" runat="server" Text="修改" />
                    <asp:Button ID="Button13" runat="server" Text="删除" />
                </ItemTemplate>
            </asp:TemplateField>

//数据绑定
protected void datebing()
    {
        try
        {
            SqlConnection myconn = new SqlConnection(publicclass.getconnstr());
            myconn.Open();
            string sqlcomm = "select * from UF_OWNERCOMM";
            SqlDataAdapter myda = new SqlDataAdapter(sqlcomm, myconn);
            DataSet myds = new DataSet();
            myda.Fill(myds, "UF_OWNERCOMM");
            GridView1.DataSource = myds;
            GridView1.DataKeyNames = new string[] { "UF_OWNERCOMM_ID" };
            GridView1.DataBind();
            myconn.Close();
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }




//后台删除功能代码
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        try
        {
            string sqlcom = "delete from  UF_OWNERCOMM where UF_OWNERCOMM_ID = '" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
            SqlConnection myconn = new SqlConnection(publicclass.getconnstr());
            myconn.Open();
            int i = new SqlCommand(sqlcom, myconn).ExecuteNonQuery();
            if (i > 0)
            {
                Response.Write("<script language=javascript>window.alert('确定要删除吗?')</script>");
            }
            else
            {
                Response.Write("<script language=javascript>window.alert('对不起,出现错误?')</script>");
            }
            myconn.Close();
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
        finally
        {
            datebing();
        }
    }



  //批量删除
    protected void Button8_Click(object sender, EventArgs e)
    {
        string ggID = "";
        foreach (GridViewRow row1 in GridView1.Rows)
        {
            if (((CheckBox)row1.FindControl("checkbox1")).Checked)
            {
                try
                {
                    ggID = this.GridView1.DataKeys[row1.DataItemIndex].Value.ToString();
                    SqlConnection myconn = new SqlConnection(publicclass.getconnstr());
                    myconn.Open();
                    string sqlcom = "delete from UF_OWNERCOMM where UF_OWNERCOMM_ID = '" + ggID + "'";
                    SqlCommand mycommand = new SqlCommand(sqlcom, myconn);
                    mycommand.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                }
            }
        }
        Response.Write("<script language=javascript>window.alert('确定要删除吗?')</script>");
        datebing();
    }



 //全选
    protected void Button6_Click(object sender, EventArgs e)
    {
        try
        {
            foreach (GridViewRow row in GridView1.Rows)
            {
                CheckBox ck = (CheckBox)row.FindControl("checkbox1");
                if (ck.Checked)
                {
                    ck.Checked = true;
                }
                else
                {
                    ck.Checked = true;
                }
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }
    //取消全选
    protected void Button7_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in GridView1.Rows)
        {
            CheckBox ck = (CheckBox)row.FindControl("checkbox1");
            {
                if (ck.Checked)
                {
                    ck.Checked = false;
                }
                else
                {
                    ck.Checked = false;
                }
            }
        }
    }
搜索更多相关主题的帖子: gridview 数据 
2008-06-20 14:39
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
收藏
得分:0 
我想知道  在gridview里模板项里放置2个LinkButton  分别起名  编辑和删除
如何实现

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-06-23 11:53
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
收藏
得分:0 
我在commandname里写的delete事件   可以删除了

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-06-24 08:52
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
收藏
得分:0 
www.也不错

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-06-28 15:05
快速回复:gridview操作数据问题?超紧急
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.041386 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved