[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Datagrid 2.0

Posted on 2009-05-13
8
Medium Priority
?
434 Views
Last Modified: 2012-05-06
I have a datagrid in C# and I would like my first column to have allow a user to delete the row. However, I would also like to have a javascript alert pop up asking the user if they are sure they would like to delete this message when the delete is clicked. Can this be done  and if so how do I go about doing this.


<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" O
            DataKeyNames="ID" AutoGenerateColumns="False" OnRowDeleted="GridView1_RowDeleted"
            DataSourceID="SqlDataSource1" CellPadding="3" CellSpacing="2" GridLines="None"
            PageSize="50">
            <RowStyle BackColor="#E6E8FC" BorderStyle="None" Font-Names="Verdana" 
                Font-Size="10pt" />
            <Columns>
                
                <%--<asp:CommandField DeleteText="Delete" ShowDeleteButton="True" 
                    ButtonType="Image" DeleteImageUrl="~/images/delete.jpg" />--%>
                
                <asp:BoundField DataField="datecreated" HeaderText="Date " 
                    SortExpression="datecreated" />
                <asp:BoundField DataField="title" HeaderText="Title" SortExpression="title" />
                <asp:BoundField DataField="checked_catalogue" HeaderText="Checked Catalogue" 
                    SortExpression="checked_catalogue" />
                <asp:BoundField DataField="a_lastname" HeaderText="Author Last Name" 
                    SortExpression="a_lastname" />
                <asp:BoundField DataField="a_firstname" HeaderText="Author First Name" 
                    SortExpression="a_firstname" />
                <asp:BoundField DataField="publisher" HeaderText="Publisher" 
                    SortExpression="publisher" />
                <asp:BoundField DataField="publication_date" HeaderText="Publication Date" 
                    SortExpression="publication_date" />
                <asp:BoundField DataField="ISBN" HeaderText="ISBN" SortExpression="ISBN" />
                <asp:BoundField DataField="how_you_hear" HeaderText="How U Hear" 
                    SortExpression="how_you_hear" />
                <asp:BoundField DataField="audience" HeaderText="Audience" 
                    SortExpression="audience" />
                <asp:BoundField DataField="additional_info" HeaderText="Additional_Info" 
                    SortExpression="additional_info" />
                <asp:BoundField DataField="p_name" HeaderText="Patron Name" 
                    SortExpression="p_name" />
                <asp:BoundField DataField="library_card_no" HeaderText="Library Card No" 
                    SortExpression="library_card_no" />
                <asp:BoundField DataField="place_hold" HeaderText="Place Hold" 
                    SortExpression="place_hold" />
                <asp:BoundField DataField="pick_up_location" HeaderText="P.U. Location" 
                    SortExpression="pick_up_location" />
            </Columns>
            <PagerStyle BackColor="#252D6C" Font-Names="Verdana" Font-Size="8pt" 
                ForeColor="White" />
            <HeaderStyle BackColor="#252D6C" Font-Names="Verdana" Font-Size="8pt" 
                ForeColor="White" />
            <AlternatingRowStyle BackColor="White" Font-Names="Verdana" 
                Font-Overline="False" Font-Size="10pt" />
        </asp:GridView>

Open in new window

0
Comment
Question by:mockweb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 4

Expert Comment

by:baiju_nagori
ID: 24378442
Hi

On code behind add following code


Protected Sub GridView1_RowDataBound(ByVal sender As Object, _ ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _ Handles GridView1.RowDataBound 
If e.Row.RowType = DataControlRowType.DataRow Then ' reference the Delete LinkButton 
Dim db As ImageButton = CType(e.Row.Cells(0).Controls(0), ImageButton) ' Get information about the product bound to the row 
 
db.OnClientClick = "return confirm('Are you certain you want to delete the product?');"
 
 End If
 
 End Sub

Open in new window

0
 

Author Comment

by:mockweb
ID: 24378498
I am using c#
0
 
LVL 4

Expert Comment

by:baiju_nagori
ID: 24378876
Bookmark this link http://www.developerfusion.com/tools/convert/vb-to-csharp/

Here is the converted code.



protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow) {
        // reference the Delete ImageButton 
        ImageButton db = (ImageButton)e.Row.Cells(0).Controls(0);
        db.OnClientClick = "return confirm('Are you certain you want to delete the product?');";
    }
}

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mockweb
ID: 24384837
i get the following error message
No overload for 'GridView1_RowDeleted' matches delegate 'System.Web.UI.WebControls.GridViewDeletedEventHandler'
0
 
LVL 4

Expert Comment

by:baiju_nagori
ID: 24388886
I am not sure how you are getting error for GridView1_RowDeleted when my solution uses GridView1_RowDataBound.

Try removing GridView1_RowDeleted and see if what I proposed works or not.


0
 

Author Comment

by:mockweb
ID: 24388990
no i am still getting an error
No overload for 'GridView1_RowDataBound' matches delegate 'System.Web.UI.WebControls.GridViewDeletedEventHandler'
0
 
LVL 4

Accepted Solution

by:
baiju_nagori earned 2000 total points
ID: 24389995
I think there is a problem on your HTML code.

Can you check for this?
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound">
 <Columns>
  <asp:CommandField ButtonType="Button" HeaderText="Del" ShowDeleteButton="True" ShowHeader="True" />
 </Columns>
</asp:GridView>
 
    protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
    {
if (e.Row.RowType == DataControlRowType.DataRow) {
        // reference the Delete ImageButton 
        ImageButton db = (ImageButton)e.Row.Cells(0).Controls(0);
        db.OnClientClick = "return confirm('Are you certain you want to delete the product?');";
    }
 
    }

Open in new window

0
 

Author Comment

by:mockweb
ID: 24424055
now i get this error:
 System.InvalidCastException: Unable to cast object of type 'System.Web.UI.WebControls.DataControlButton' to type 'System.Web.UI.WebControls.ImageButton'.

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

656 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