首页 新闻 会员 周边

asp.net Grideview使用

0
[已关闭问题]

我想在Grideview中自定义一个列为Button 我怎么做能点击这个按钮便能删除所在的行,或修改,编译。

ldllan的主页 ldllan | 初学一级 | 园豆:190
提问于:2008-12-13 00:06
< >
分享
其他回答(5)
0

使用Button的CommandName属性,再使用GridView的RowCommand事件,这样在按下Button以后就会触发GridView的RowCommand事件并传递CommandName作为参数

Gray Zhang | 园豆:17610 (专家六级) | 2008-12-13 00:31
0

如果想简单点实现的话,建议你使用GridView自带的CommandField列。这种列包含了选择、编辑(及更新)、删除三种操作按钮。

史向平 | 园豆:164 (初学一级) | 2008-12-13 08:20
0

楼上的都答得非常清楚了。。。

XBW | 园豆:404 (菜鸟二级) | 2008-12-13 09:31
0

类似这样:

前台:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
    <Columns>
        <asp:BoundField DataField="personName" />
        <asp:BoundField DataField="personAge" />
        <asp:TemplateField HeaderText="操作">
        <ItemTemplate>
            <asp:Button ID="btn_OK" runat="server" Text="确定"
            CommandArgument='<%# Eval("personName") %>' CommandName="btn_OK" />
            <asp:Button ID="btn_Cancel" runat="server" Text="取消" CommandName="btn_Cancel"
            CommandArgument='<%# Eval("personName") %>' />
        </ItemTemplate>
       </asp:TemplateField>
    </Columns>
</asp:GridView>
后台:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    //直接利用参数
    string strName = e.CommandArgument.ToString();
    //一种取得当前行的方法
    GridViewRow currRow = (GridViewRow)((Button)e.CommandSource).Parent.Parent;
    string strAge = currRow.Cells[1].Text.ToString();
    if (e.CommandName == "btn_OK")
    {
        this.TextBox1.Text = "确定按钮 " + strName + " " + strAge;
    }
    if (e.CommandName == "btn_Cancel")
    {
        this.TextBox1.Text = "取消按钮 " + strName + " " + strAge;
    }
}

这篇文章里有详细说明,你看完就明白了

 

http://freeliver54.cnblogs.com/archive/2006/02/09/327853.html

GUO Xingwang | 园豆:3885 (老鸟四级) | 2008-12-13 09:44
0

看下这个,对你学习它很有用~GridView 18种操作 <http://blog.csdn.net/fanweiwei/archive/2007/03/26/1541373.aspx>
快速预览:
GridView无代码分页排序
GridView选中,编辑,取消,删除
GridView正反双向排序
GridView和下拉菜单DropDownList结合
GridView和CheckBox结合
鼠标移到GridView某一行时改变该行的背景色方法一
鼠标移到GridView某一行时改变该行的背景色方法二
GridView实现删除时弹出确认对话框
GridView实现自动编号
GridView实现自定义时间货币等字符串格式
GridView实现用“...”代替超长字符串
GridView一般换行与强制换行
GridView显示隐藏某一列
GridView弹出新页面/弹出新窗口
GridView固定表头(不用javascript只用CSS,2行代码,很好用)
GridView合并表头多重表头无错完美版(以合并3列3行举例)
GridView突出显示某一单元格(例如金额低于多少,分数不及格等)
GridView加入自动求和求平均值小计
GridView数据导入Excel/Excel数据读入GridView

Astar | 园豆:40805 (高人七级) | 2008-12-13 09:48
0

单单删除对应行的话,试用gridview中的  command列,里面有删除  列。然后对gridview的row*的事件中绑定下数据连接方法就可以了!

Jinzhi | 园豆:240 (菜鸟二级) | 2008-12-22 20:47
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册