Datagrids are kicking my ass!! Please help

G

Guest

Ok I set up a button column to delete an individual record. Nothing happens
when I test it. Someone please help understand why. Below is the associated
coding:

DataGrid control:

<asp:datagrid id="clubdg" DataKeyField="UserID" runat="server"
GridLines="Vertical" CellPadding="2" BorderWidth="1px"
BorderColor="#CCCCFF" CssClass="txt"
AutoGenerateColumns="False" OnCancelCommand="Cancel_Click"
OnUpdateCommand="Update_Click" OnDeleteCommand="Delete_Click"
OnEditCommand="Edit_Click">
<SelectedItemStyle VerticalAlign="Top"></SelectedItemStyle>
<EditItemStyle VerticalAlign="Top"
BackColor="#000033"></EditItemStyle>
<AlternatingItemStyle VerticalAlign="Top"></AlternatingItemStyle>
<ItemStyle VerticalAlign="Top"></ItemStyle>
<HeaderStyle Font-Size="10px" Font-Names="Verdana"
Font-Bold="True" HorizontalAlign="Center"
VerticalAlign="Middle" BackColor="#000044"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Staff Name">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,"UserPrefix")%>
<%# DataBinder.Eval(Container.DataItem,"UserFName")%>
<%# DataBinder.Eval(Container.DataItem,"UserLName")%>
<BR>
Organization
ID: <%#DataBinder.Eval(Container.DataItem,"ClubID")%>
</ItemTemplate>
<EditItemTemplate>
User Prefix:<BR>
<asp:TextBox id="UserPrefix" Runat="server"></asp:TextBox><BR>
User First Name:<BR>
<asp:TextBox id="UserFName" Runat="server"></asp:TextBox><BR>
User Last Name:<BR>
<asp:TextBox id="UserLName" Runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="User Access">
<ItemTemplate>
Email Address:<br>
<%# DataBinder.Eval(Container.DataItem, "UserEmail")%>
<br>
Password: <%#
DataBinder.Eval(Container.DataItem,"UserPassword")%><br>
User Role: <%# DataBinder.Eval(Container.DataItem,
"AccessID")%><br>
<br>
<br>
Show: <%# DataBinder.Eval(Container.DataItem,"show")%><br>
Booking: <%#
DataBinder.Eval(Container.DataItem,"Bookings")%><br>
General: <%#
DataBinder.Eval(Container.DataItem,"General")%><br>
Guest List: <%#
DataBinder.Eval(Container.DataItem,"GuestList")%>
</ItemTemplate>
<EditItemTemplate>
User Email:<br>
<asp:TextBox ID="UserEmail" Runat="server"></asp:TextBox><br>
User Password:<br>
<asp:TextBox ID="UserPassword"
Runat="server"></asp:TextBox><br>
User Role:<br>
<asp:DropDownList ID="AccessID" Runat="server">
<asp:ListItem Selected="True">Select Role</asp:ListItem>
<asp:ListItem Value="Admin">Administrator</asp:ListItem>
<asp:ListItem Value="Promotor">Promotor</asp:ListItem>
<asp:ListItem Value="General Staff">General
Staff</asp:ListItem>
</asp:DropDownList><br>
Show On Contacts:
<asp:CheckBox ID="show" Runat="server"></asp:CheckBox><br>
<br>
<table class="txt" cellpadding="0" cellspacing="0"
border="0" width="100%">
<tr>
<td>in:</td>
</tr>
<tr>
<td>Bookings contact List:</td>
<td>
<asp:CheckBox ID="Bookings"
Runat="server"></asp:CheckBox></td>
</tr>
<tr>
<td>General Information:</td>
<td>
<asp:CheckBox ID="General"
Runat="server"></asp:CheckBox></td>
</tr>
<tr>
<td>Guest List:</td>
<td>
<asp:CheckBox ID="GuestList"
Runat="server"></asp:CheckBox></td>
</tr>
</table>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Staff Address">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,"UserStreetNumber")%>
<%# DataBinder.Eval(Container.DataItem, "UserAddress")%><br>
<%# DataBinder.Eval(Container.DataItem,"UserCity")%>
, <%#
DataBinder.Eval(Container.DataItem,"UserProvince")%><br />
<%# DataBinder.Eval(Container.DataItem,"UserPostal")%>
</ItemTemplate>
<EditItemTemplate>
Street Number:
<asp:TextBox ID="UserStreetNumber" Width="30"
Runat="server"></asp:TextBox><br>
Street Address:<br>
<asp:TextBox ID="UserAddress"
Runat="server"></asp:TextBox><br>
City:<br>
<asp:TextBox ID="UserCity" Runat="server"></asp:TextBox><br>
Province:<br>
<asp:TextBox ID="UserProvince"
Runat="server"></asp:TextBox><br>
Postal Code:<br>
<asp:TextBox ID="UserPostal" Runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Contact Information">
<ItemTemplate>
Phone: <%#
DataBinder.Eval(Container.DataItem,"UserPhone","{0:###-###-####}")%><br>
Fax: <%#
DataBinder.Eval(Container.DataItem,"UserFax","{0:###-###-####}")%><br>
Mobile: <%#
DataBinder.Eval(Container.DataItem,"UserMobile","{0:###-###-####}")%><br>
</ItemTemplate>
<EditItemTemplate>
Phone:<br>
<asp:TextBox ID="UserPhone" Runat="server"></asp:TextBox><br>
Fax:<br>
<asp:TextBox ID="UserFax" Runat="server"></asp:TextBox><br>
Mobile:<br>
<asp:TextBox ID="UserMobile" Runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="LinkButton"
UpdateText="Update" HeaderText="User Management" CancelText="Cancel"
EditText="Edit Row"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete Record"
CommandName="Delete_Click" HeaderText="Delete Record"></asp:ButtonColumn>
</Columns>
</asp:datagrid>

CodeBehind:

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
BindData();
}
}

public void Edit_Click(Object sender, DataGridCommandEventArgs e)
{
clubdg.EditItemIndex=e.Item.ItemIndex;
BindData();
}
public void Delete_Click(Object sender, DataGridCommandEventArgs e)
{
dsclub=new DataSet();
clubconn=new SqlConnection(strclubconn);
clubcmd=new SqlCommand("dt_UserDelete",clubconn);
clubcmd.CommandType=CommandType.StoredProcedure;
clubcmd.Parameters.Add(Globals.User_tbl_UserID_PARM,System.Data.SqlDbType.Int,4,e.Item.ItemIndex.ToString());
clubadapt.SelectCommand=clubcmd;
clubconn.Open();
BindData();

}
public void Update_Click(Object sender, DataGridCommandEventArgs e)
{
}
public void Cancel_Click(Object sender, DataGridCommandEventArgs e)
{
clubdg.EditItemIndex=-1;
BindData();
}
public void BindData()
{
dsclub=new DataSet();
clubconn=new SqlConnection(strclubconn);
clubconn.Open();
clubadapt=new SqlDataAdapter(userselect,clubconn);
clubconn.Close();
clubadapt.Fill(dsclub,"UserTbl");

clubdg.DataSource=dsclub;
clubdg.DataBind();
}

Stored Procedure:
CREATE PROCEDURE dbo.dt_UserDelete
(
@UserID int
)
AS
SET NOCOUNT ON
DELETE
FROM
User_tbl
WHERE
UserID=@UserID
return 0
GO

As well I set up a class called Globals() that names all the stored
procedures and parameter names as well as field names on to a seperate file
so that I would have all the constants in one location:

Globals() Class:
public class Globals
{
// Field name constents for User_tbl_
public const string User_tbl_UserID_Field = "UserID";
public const string User_tbl_ClubID_Field = "ClubID";
public const string User_tbl_AccessID_Field = "AccessID";
public const string User_tbl_Position_Field = "PositionID";
public const string User_tbl_UserPrefix_Field = "UserPrefix";
public const string User_tbl_UserFName_Field = "UserFName";
public const string User_tbl_UserLName_Field = "UserLName";
public const string User_tbl_UserEmail_Field = "UserEmail";
public const string User_tbl_UserPassword_Field = "UserPassword";
public const string User_tbl_UserStreetNumber_Field = "UserStreetNumber";
public const string User_tbl_UserAddress_Field = "UserAddress";
public const string User_tbl_UserCity_Field = "UserCity";
public const string User_tbl_UserProvince_Field = "UserProvince";
public const string User_tbl_UserPostal_Field = "UserPostal";
public const string User_tbl_UserPhone_Field = "UserPhone";
public const string User_tbl_UserFax_Field = "UserFax";
public const string User_tbl_UserMobile_Field = "UserMobile";
public const string User_tbl_UserNote_Field = "UserNote";
public const string User_tbl__Date_Field = "_Date";
public const string User_tbl_show_Field = "show";
public const string User_tbl_Bookings_Field = "Bookings";
public const string User_tbl_General_Field = "General";
public const string User_tbl_GuestList_Field = "GuestList";
public const string User_tbl_BarInfo_Field = "BarInfo";
// Stored Procedure name constents.
public const string UserDelete_SP = "dt_UserDelete";
public const string UserInsert_SP = "dt_UserInsert";
public const string UserUpdate_SP = "dt_UserUpdate";

// Stored Procedure parameter name constents for User_tbl_
public const string User_tbl_UserID_PARM = "@UserID";
public const string User_tbl_ClubID_PARM = "@ClubID";
public const string User_tbl_AccessID_PARM = "@AccessID";
public const string User_tbl_Position_PARM = "@PositionID";
public const string User_tbl_UserPrefix_PARM = "@UserPrefix";
public const string User_tbl_UserFName_PARM = "@UserFName";
public const string User_tbl_UserLName_PARM = "@UserLName";
public const string User_tbl_UserEmail_PARM = "@UserEmail";
public const string User_tbl_UserPassword_PARM = "@UserPassword";
public const string User_tbl_UserStreetNumber_PARM = "@UserStreetNumber";
public const string User_tbl_UserAddress_PARM = "@UserAddress";
public const string User_tbl_UserCity_PARM = "@UserCity";
public const string User_tbl_UserProvince_PARM = "@UserProvince";
public const string User_tbl_UserPostal_PARM = "@UserPostal";
public const string User_tbl_UserPhone_PARM = "@UserPhone";
public const string User_tbl_UserFax_PARM = "@UserFax";
public const string User_tbl_UserMobile_PARM = "@UserMobile";
public const string User_tbl_UserNote_PARM = "@UserNote";
public const string User_tbl__Date_PARM = "@_Date";
public const string User_tbl_show_PARM = "@show";
public const string User_tbl_Bookings_PARM = "@Bookings";
public const string User_tbl_General_PARM = "@General";
public const string User_tbl_GuestList_PARM = "@GuestList";
public const string User_tbl_BarInfo_PARM = "@BarInfo";
}
Please help someone. I don't understand why the Delete_Click Event is not
working.
Sam-
 
L

Lucas Tam

Ok I set up a button column to delete an individual record. Nothing
happens when I test it. Someone please help understand why. Below is
the associated coding:

Did you attach the Delete_Click button to your Button Event Handler?

I believe in a datagrid all button clicks are handled by the ItemCommand
event handler. Since the ItemCommand event handles all button commands,
you'll know to figure out which button is clicked by checking the Button's
command name/command argument. Once you know which button is clicked, you
can run the appropriate subprocedure.
 
J

JohnFol

Does the stored procedure get called?
Does the Delete_Click routine get called?
Are any exceptions raised?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top