However I would like the ability to deleted a row. I cannot get that to work though. Below is my code. What exactly do I need to do to remove a row from a datagrid? I am looking at
DeleteCommand=""
but have no idea what to try. I have tested several things and referenced
http://msdn.microsof...287(VS.71).aspx
for helpbut am not getting anywhere.
Advice would be awesome.
Thanks
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Pokedex</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Welcome to my Pokedex
<asp:GridView ID="GridView1" AllowSorting="True" AllowPaging="True" Runat="server"
DataSourceID="SqlDataSource1" AutoGenerateEditButton="True"
AutoGenerateColumns="False" onrowcancelingedit="GridView1_RowCancelingEdit"
onrowediting="GridView1_RowEditing" onrowupdating="GridView1_RowUpdating">
<Columns>
<asp:BoundField DataField="PokemonName" HeaderText="PokemonName"
SortExpression="PokemonName" />
<asp:BoundField DataField="PokemonType" HeaderText="PokemonType"
SortExpression="PokemonType" />
<asp:BoundField DataField="HP" HeaderText="HP"
SortExpression="HP" />
<asp:BoundField DataField="Weakness" HeaderText="Weakness"
SortExpression="Weakness" />
<asp:BoundField DataField="Strength" HeaderText="Strength"
SortExpression="Strength" />
<asp:CommandField HeaderText="Delete Pokemon" ShowDeleteButton="True"
ShowHeader="True" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:pokemondatabaseConnectionString %>"
SelectCommand="SELECT * FROM [PokemonData]"
[b]DeleteCommand=""[/b]
UpdateCommand="Update PokemonData SET Weakness=@Weakness, Strength=@Strength, HP=@HP, PokemonType=@PokemonType WHERE PokemonName=@PokemonName"
></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
}
private void DataGrid1_DeleteCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
int rowToDelete = e.Item.ItemIndex;
// Add code to delete row from data source.
GridView1.DataBind();
}
}

New Topic/Question
Reply



MultiQuote



|