首页 新闻 会员 周边 捐助

三层,Griview

0
悬赏园豆:5 [待解决问题]

asp.net 里面怎么通过Gridview删除数据库里的数据

张 开的主页 张 开 | 初学一级 | 园豆:195
提问于:2011-04-18 18:13
< >
分享
所有回答(1)
0

1)aspx 页面如下

<asp:GridView ID="gvNewsManage" DataKeyNames="NewsID"
            runat="server" AutoGenerateColumns="False"
            onrowdeleting="gvNewsManage_RowDeleting"
            AllowPaging="True"
        onrowdatabound="gvNewsManage_RowDataBound">      
            <PagerSettings Visible="False" />
            <Columns>
                <asp:BoundField DataField="NewsID" HeaderText="ID" />
                 <asp:TemplateField HeaderText="选择">
                    <ItemTemplate>
                        <asp:CheckBox ID="chkbSelect" runat="server">
                        </asp:CheckBox>
                    </ItemTemplate>
                     <ItemStyle Width="20px" />
                </asp:TemplateField>
                <asp:TemplateField HeaderText="新闻标题">                   
                    <ItemTemplate>
                        <asp:Label ID="lblNewsTitle" runat="server" Text='<%# FormatString(Eval("NewsTitle").ToString()) %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
              
                <asp:HyperLinkField DataNavigateUrlFields="NewsID" DataNavigateUrlFormatString="UpdateNews.aspx?Value={0}"
                    HeaderText="修改" Text="修改" />
                <asp:TemplateField HeaderText="删除">
                    <ItemTemplate>
                        <asp:LinkButton ID="lkbtnDelete" OnClientClick="return confirm('您确认删除该记录吗?');" runat="server" CommandName="Delete" Font-Names="宋体" Font-Strikeout="False" Font-Underline="False" ForeColor="Black">删除</asp:LinkButton>&nbsp;        
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
     </asp:GridView>

2) cs 代码段:

protected

void gvNewsManage_RowDeleting(object sender, GridViewDeleteEventArgs e)

{

 

int id = Convert.ToInt32(gvNewsManage.DataKeys[e.RowIndex].Value.ToString());

 

if (news.Delete(id) > 0)

{

BindData(e.RowIndex);

MagicAjax.

AjaxCallHelper.WriteAlert("");

}

 

else

{

MagicAjax.

AjaxCallHelper.WriteAlert("");

}

}

DYStudio.Net | 园豆:1747 (小虾三级) | 2011-04-18 21:56
可以了
支持(0) 反对(0) 张 开 | 园豆:195 (初学一级) | 2011-04-19 12:17
欢迎入群讨论 群号:149385300
支持(0) 反对(0) DYStudio.Net | 园豆:1747 (小虾三级) | 2011-04-19 12:18
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册