Solved

Can someone Convert this from the VB.NET to the C# ?

Posted on 2006-11-04
11
1,000 Views
Last Modified: 2008-08-26


Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting  

0
Comment
Question by:Scripter25
  • 7
  • 3
11 Comments
 
LVL 27

Accepted Solution

by:
Sammy earned 500 total points
ID: 17874626
protected void GridView1_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e) {
    }

and make sure you gridview has the following
onrowdeleting="GridView1_RowDeleting"  

take a look here for more on the subject
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdeleting(VS.80).aspx

HTH
0
 

Author Comment

by:Scripter25
ID: 17875171
Ok I think you are correct but I am having an issue that is preventing me from testing it out,,,


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
0
 

Author Comment

by:Scripter25
ID: 17875188
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
0
 

Author Comment

by:Scripter25
ID: 17875190
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(Object 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_RowDeleting"  
0
 

Author Comment

by:Scripter25
ID: 17875283
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.GridViewDeletedEventHandler'      C:\Documents and Settings\Scott\My Documents\Visual Studio 2005\WebSites\shotdrive\upload.aspx      18
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Scripter25
ID: 17875296
This is my code

        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
            AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333"
            GridLines="None" Style="z-index: 103; left: 160px; position: absolute; top: 204px" OnRowDeleted="GridView1_RowDeleting" >



    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
    }
0
 

Author Comment

by:Scripter25
ID: 17875304
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
0
 
LVL 27

Expert Comment

by:Sammy
ID: 17876068
can you post the complete code?
0
 
LVL 27

Expert Comment

by:Sammy
ID: 17876233
something to look at is this walkthrough from MSDN
http://msdn2.microsoft.com/en-us/library/ms972940.aspx

0
 

Author Comment

by:Scripter25
ID: 17877620
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
0
 

Expert Comment

by:A-BM
ID: 22315265
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:LinkButton>
</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.CommandArgument)
 
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now