最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

asp.net 不用GridView自帶刪除功能,刪除一行數(shù)據(jù)

 更新時間:2009年11月30日 20:39:19   作者:  
數(shù)據(jù)表一定要有個ID的主鍵值,你的gridview要設(shè)定一下DataKeyNames="ID"這個屬性值,接下的事件就好多了,寫個OnRowDeleting事件就可以了。
前臺代碼:
復(fù)制代碼 代碼如下:

<asp:GridView ID="GridLog" runat="server"
AutoGenerateColumns="False" CellPadding="4" DataKeyNames="ID"
BorderColor="#333" BorderStyle="solid" BorderWidth="1"
OnRowDeleting="PublicGridRowDeleting"
GridLines="None" Width="98%" ForeColor="#333333">
<FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" />
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="false"
ReadOnly="True"
SortExpression="ID" >
<ItemStyle HorizontalAlign="Center" Width="20px" />
</asp:BoundField>
<asp:TemplateField HeaderText="刪除" ShowHeader="False">
<ItemStyle HorizontalAlign="Center" Width="40px" />
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
CausesValidation="False" CommandName="Delete" OnClientClick="return confirm('您確認(rèn)刪
除?');" Text="刪除"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333"
/>
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center"
/>
<HeaderStyle BackColor="#5A799C" ForeColor="White" Height="22px" />
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#2461BF" />
<EmptyDataTemplate>
日志庫暫時為空!
</EmptyDataTemplate>
</asp:GridView>

CS代碼
復(fù)制代碼 代碼如下:

protected void PublicGridRowDeleting(object sender, GridViewDeleteEventArgs e)
{
string strID = GridLog.DataKeys[e.RowIndex].Value.ToString();//strID就是該行的ID
string strSQL = "Delete from table " +
" WHERE id = " + strID;
//執(zhí)行刪除
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT
LANGUAGE='javascript'>alert('刪除成功!');</script>");
GridBind();
}

關(guān)鍵是設(shè)定好DataKeyNames后,可以靠 string strID = GridLog.DataKeys
[e.RowIndex].Value.ToString();獲得選擇列的ID值 然后用這個ID執(zhí)行刪除就可以了 。

相關(guān)文章

最新評論

长泰县| 莱州市| 阿荣旗| 阳信县| 岱山县| 九台市| 凤阳县| 灵寿县| 黑河市| 镇安县| 广饶县| 阿勒泰市| 大方县| 台湾省| 革吉县| 苏尼特右旗| 昭平县| 应城市| 英超| 耿马| 栾城县| 湘潭市| 衡水市| 邹平县| 江北区| 秦安县| 东城区| 丹巴县| 普兰店市| 依安县| 安岳县| 庆云县| 襄汾县| 云阳县| 天长市| 汕头市| 高碑店市| 凤冈县| 太谷县| 深圳市| 来凤县|