标题:gridview操作数据问题?超紧急
只看楼主
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
结帖率:100%
 问题点数:0 回复次数:9 
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: 4
来 自:上海
等 级:贵宾
威 望:14
帖 子:806
专家分:44
注 册:2007-6-28
得分:0 
话都说不清楚...

Flying without wings
2008-06-20 19:23
小乌龟
Rank: 2
等 级:新手上路
威 望:4
帖 子:1291
专家分:0
注 册:2007-9-28
得分:0 
please show the error information!
2008-06-20 19:48
gupiao175
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:40
帖 子:1787
专家分:7527
注 册:2007-6-27
得分:0 
没看董!好复杂啊!
没看董!好复杂啊!

Q:1428196631,百度:开发地 即可找到我,有事请留言!
2008-06-23 11:42
雪雨星风
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
cyyu_ryh
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:1899
专家分:176
注 册:2006-10-21
得分:0 
用gridciew_rowbind事件
通过设置conmandname来实现

有事无事都密我. MSN: cyyu_ryh@hotmail.co.jp E-mail: cyyu_ryh@
2008-06-23 12:54
冰彩虹
Rank: 4
来 自:上海
等 级:贵宾
威 望:14
帖 子:806
专家分:44
注 册:2007-6-28
得分:0 
[bo][un]雪雨星风[/un] 在 2008-6-23 11:53 的发言:[/bo]

我想知道  在gridview里模板项里放置2个LinkButton  分别起名  编辑和删除
如何实现




建议先多看看基础教程吧

以上的实现GridView直接有提供

Flying without wings
2008-06-23 19:59
雪雨星风
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
letian584
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2008-3-28
得分:0 
最苯的方法
<asp:TemplateField HeaderText="操作">
                <ItemTemplate>
                    <asp:Button ID="Button11" runat="server" Text="审批" />
      </ItemTemplate>
            </asp:TemplateField>
<asp:TemplateField HeaderText="操作">
                <ItemTemplate>
                    <asp:Button ID="Button13" runat="server" Text="删除" />
                </ItemTemplate>
            </asp:TemplateField>
这样搞3个也可以 嘿嘿 方法是最笨的 但是也能有用 记得数据绑定就OK啦
2008-06-28 17:44



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-220216-1-1.html




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

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