Add Delete button to GridView

  • Thread starter Thread starter pargat.singh
  • Start date Start date
P

pargat.singh

I want to add delete button to grid view and pass all the clicked row
parameters. Can someone please tell me how can i do this? Below are my
codes.

Thanks in advance.

<asp:GridView ID="GridView2" EmptyDataText="No Data Found"
GridLines="None" CssClass="gridview" AlternatingRowStyle-
CssClass="even" Width="620px" runat="server"
AutoGenerateColumns="False"
DataSourceID="ObjectDataSource1" AllowSorting="True" >
<AlternatingRowStyle CssClass="even" />
<Columns>
<asp:BoundField DataField="submit_date"
HeaderText="Submit Date &amp; Time (GMT-5)"
SortExpression="submit_date" />
<asp:BoundField DataField="id_no"
HeaderText="Confirmation No." SortExpression="id_no" />
<asp:BoundField HtmlEncode="False"
DataFormatString="{0:C}" DataField="grant_price" HeaderText="Grant
Price" SortExpression="grant_price" />
<asp:BoundField DataField="grant_date"
HeaderText="Grant Date" SortExpression="grant_date" >
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="plan_id"
HeaderText="Plan ID" SortExpression="plan_id" />
<asp:BoundField DataField="exercise_options"
HeaderText="Options to Exercise" SortExpression="exercise_options" >
<ItemStyle HorizontalAlign="Right" />
<HeaderStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox Visible="false"
ID="txtAP" Text='<%# DataBinder.Eval(Container.DataItem, "a_no") %>'
runat="server"></asp:TextBox>
<asp:TextBox Visible="false"
ID="txtFP" Text='<%# DataBinder.Eval(Container.DataItem, "f_no") %>'
runat="server"></asp:TextBox>
<asp:TextBox Visible="false"
ID="txtPP" Text='<%# DataBinder.Eval(Container.DataItem, "p_code") %>'
runat="server"></asp:TextBox>
<asp:TextBox Visible="false"
ID="txtOP" Text='<%# DataBinder.Eval(Container.DataItem, "o_no") %>'
runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>



<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetPendingRecordsDetail"
TypeName="XXXXX">
<SelectParameters>
<asp:ControlParameter ControlID="clientIDH"
Name="clientID" PropertyName="Value"
Type="String" />
<asp:ControlParameter ControlID="baseIDH"
Name="baseID" PropertyName="Value" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
 
This my boot you in the right direction:

http://www.ben-rush.net/blog/PermaLink.aspx?guid=fd882660-8c7b-4a9e-9...

...and if it does not let me know.

--
~~~~~~~~~~~
Ben Rushhttp://www.ben-rush.net/blog









- Show quoted text -

Thanks. In my case e.CommandArgument is coming blank. Below is the
info from CommandSource.

?e.CommandSource
{Text = "Delete"}
base {System.Web.UI.WebControls.WebControl}: {Text = "Delete"}
CausesValidation: true
CommandArgument: ""
CommandName: ""
OnClientClick: ""
PostBackUrl: ""
Text: "Delete"
UseSubmitBehavior: true
ValidationGroup: ""

Thanks,
Pargat
 
What happens if you set the CommandName? This is interesting to me because
it always worked for me, but I've always seemed to have used the CommandName
in my particular scenarios.

Try setting it to something like COMMANDDELETE or something like that for
that particular column and see if you get a CommandArgument.

Please let me know if this works.
 
Back
Top