[RESOLVED] gridview delete button
Hi team, im using gridview delete button with datasource markup:
source Code:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:direct_deliveryConnectionString %>"
SelectCommand="select pk_ddlvryDetailID,fk_grfdetailID,itemDescription,qty,uom,rate,(qty*rate) as Amount
from qddlvrydetails
where fk_ddlvryMasterID=@id"
DeleteCommand="delete
from tblddlvrydetails
where pk_ddlvrydetailid=@id">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="0" Name="id" QueryStringField="ID" />
</SelectParameters>
<DeleteParameters>
<asp:ControlParameter ControlID="GridView1" Name="id" PropertyName="SelectedValue" />
</DeleteParameters>
</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.
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
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?
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
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.
Re: [RESOLVED] gridview delete button
That sounds about right.
Glad to hear that you got it working the way you want it!
Gary