Results 1 to 6 of 6

Thread: [RESOLVED] gridview delete button

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Resolved [RESOLVED] gridview delete button

    Hi team, im using gridview delete button with datasource markup:

    source Code:
    1. <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:direct_deliveryConnectionString %>"
    2.                 SelectCommand="select pk_ddlvryDetailID,fk_grfdetailID,itemDescription,qty,uom,rate,(qty*rate) as Amount from qddlvrydetails where fk_ddlvryMasterID=@id"
    3.                    DeleteCommand="delete from tblddlvrydetails where pk_ddlvrydetailid=@id">
    4.                 <SelectParameters>
    5.                     <asp:QueryStringParameter DefaultValue="0" Name="id" QueryStringField="ID" />
    6.                 </SelectParameters>
    7.                 <DeleteParameters>
    8.                     <asp:ControlParameter ControlID="GridView1" Name="id" PropertyName="SelectedValue" />
    9.                 </DeleteParameters>
    10.             </asp:SqlDataSource>

    I created a parameter named @ID which will received value from grid selectedvalue whenever the delete button fire up but whenever i do that the will just postback without delete the row.

    Such case do i need to add code behind? Or im doing it wrong again.

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: gridview delete button

    Hey,

    I would suggest that you do one of two things...

    1) If you are going to stick with using the SqlDataSource, then make life easier on yourself, and have the SqlDataSource do the work of deleting your rows. There is an article here that talks you through what you would need to do to get this working:

    http://msdn.microsoft.com/en-us/library/ms972940.aspx

    Or, if you want to take a little bit more control, see this article:

    http://www.asp.net/data-access/tutor...ldatasource-vb

    Notice that the DeleteParameter is named the same as the primary key column from the SelectCommand.

    2) Stop using the SqlDataSource completely, and take ownership of the database operations yourself.

    Gary

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: gridview delete button

    hey,

    the 2nd link is flawless it work like magic XD. In essence i need to provide a confirmation upon delete. Unfortunately, the GridView's CommandField does not include an OnClientClick property instead the workaround to have a linkedbutton or imagebutton. Huh i have nightmare working in linkedbutton though XD.
    How can i add image linkbutton?
    Last edited by jlbantang; Jul 24th, 2010 at 09:58 AM.

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: gridview delete button

    Okay, what am I missing? What is XD?

    One suggestion would be to use a TemplateField, rather than a CommandField, and in there, place the controls that you want, but still bind the same information as you currently are.

    Gary

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: gridview delete button

    Yes TemplateField works as you suggest. And for adding image in linkbutton I added
    Code:
    <img src='Images/delete.gif' alt='Delete' border='0'/>
    under linkbutton text property.

  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] gridview delete button

    That sounds about right.

    Glad to hear that you got it working the way you want it!

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width