Scripter25
asked on
Can someone Convert this from the VB.NET to the C# ?
Protected Sub GridView1_RowDeleting(ByVa
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok disregard the last statement I just figured out that in order for those options to be available you have to have a primary key set to the table
ASKER
Aight now I tested out what I have but it does not work
though I do not understand fully your reply on this can you be a bit more descriptive
This is what I have
void GridView1_RowDeleting(Obje ct sender, GridViewDeleteEventArgs e)
{
// Cancel the delete operation if the user attempts to remove
// the last record from the GridView control.
if (GridView1.Rows.Count <= 1)
{
Response.Write("I Hope this works");
}
}
But what are you talking about in regards to the onrowdeleting="GridView1_R owDeleting "
though I do not understand fully your reply on this can you be a bit more descriptive
This is what I have
void GridView1_RowDeleting(Obje
{
// Cancel the delete operation if the user attempts to remove
// the last record from the GridView control.
if (GridView1.Rows.Count <= 1)
{
Response.Write("I Hope this works");
}
}
But what are you talking about in regards to the onrowdeleting="GridView1_R
ASKER
ok Now I figured out what you were talking about regarding onrowdeleting but this is what I get now
Error 1 No overload for 'GridView1_RowDeleting' matches delegate 'System.Web.UI.WebControls .GridViewD eletedEven tHandler' C:\Documents and Settings\Scott\My Documents\Visual Studio 2005\WebSites\shotdrive\up load.aspx 18
Error 1 No overload for 'GridView1_RowDeleting' matches delegate 'System.Web.UI.WebControls
ASKER
This is my code
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False " CellPadding="4" DataSourceID="SqlDataSourc e1" ForeColor="#333333"
GridLines="None" Style="z-index: 103; left: 160px; position: absolute; top: 204px" OnRowDeleted="GridView1_Ro wDeleting" >
protected void GridView1_RowDeleting(obje ct sender, GridViewDeleteEventArgs e)
{
}
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False
GridLines="None" Style="z-index: 103; left: 160px; position: absolute; top: 204px" OnRowDeleted="GridView1_Ro
protected void GridView1_RowDeleting(obje
{
}
ASKER
Ok I figured out that I was using OnRowDeleted when I should have been using OnRowDeleting
But I still have the problem that it is not deleting any rows
But I still have the problem that it is not deleting any rows
can you post the complete code?
something to look at is this walkthrough from MSDN
http://msdn2.microsoft.com/en-us/library/ms972940.aspx
http://msdn2.microsoft.com/en-us/library/ms972940.aspx
ASKER
Figured it all out I was just missing
DataKeyNames="ID" in the GridView. I didnt even have to add the primary key to the Gridview to show. although for future readers of this as to not confuse the Primary Key does have to be included in the SQLDataSource in order for it to work.
Thank you to everyone that helped with this
DataKeyNames="ID" in the GridView. I didnt even have to add the primary key to the Gridview to show. although for future readers of this as to not confuse the Primary Key does have to be included in the SQLDataSource in order for it to work.
Thank you to everyone that helped with this
Dear,
Don't use delete keyword, try to use another keyword just like "Remove". Because the delete keyword is a reserved keyword in 'SqlDataSource1'
Just like :
<ItemTemplate>
<asp:LinkButton ID="LinkButton23" runat="server" CausesValidation="False" CommandName="Remove" Text="Remove"></asp:LinkBu tton>
</ItemTemplate>
You can use commandArgument keyword to delete selected row from gridview
as CommandArgument = '<%# Eval("Name of the Your Field") %>'
then in item command
if e.commandargument = "Remove";
call function or sub for deleting the row from the datagrid
YouFunction(E.CommandArgum ent)
Don't use delete keyword, try to use another keyword just like "Remove". Because the delete keyword is a reserved keyword in 'SqlDataSource1'
Just like :
<ItemTemplate>
<asp:LinkButton ID="LinkButton23" runat="server" CausesValidation="False" CommandName="Remove" Text="Remove"></asp:LinkBu
</ItemTemplate>
You can use commandArgument keyword to delete selected row from gridview
as CommandArgument = '<%# Eval("Name of the Your Field") %>'
then in item command
if e.commandargument = "Remove";
call function or sub for deleting the row from the datagrid
YouFunction(E.CommandArgum
ASKER
When I try to do the delete it provides the following error
Deleting is not supported by data source 'SqlDataSource1' unless DeleteCommand is specified.
Which is pretty understandable error for me the only problem is is when I go to the 'SqlDataSource1' and choose "Configure Data Source" when I attempt to add "Update, Delete" functionality to it it is just greyed out.
The SQL statment for that 'SqlDataSource1' is a simple select