Click here to Skip to main content
15,910,234 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
How to delete gridview row to be deleted when dropdownlist is selected another value?
Posted
Comments
Sharmanuj 23-Jul-14 2:21am    
Hi Sujay,

could you provide some more information regarding what you want to achieve.
sujay anand 23-Jul-14 2:50am    
Hi Sharmanuj, As I have used gridview to display datas.In that i m using Dropdownlist. I want answer when I select dropdownlist, I want to delete the whoole row. For eg: In dropdownlist I m using Poor and Good. when i select poor, the row itself should be deleted.
Thanks7872 23-Jul-14 2:25am    
Its better to update the underlying datasource as GridView is just a matter of display.
Arunprasath Natarajan 23-Jul-14 2:57am    
Try RowCommand
sujay anand 23-Jul-14 3:01am    
This is the code m using Please say me in coding....


<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="username"
DataSourceID="SqlDataSource1" onrowcommand="GridView1_RowCommand">
<columns> <asp:TemplateField HeaderText="Username" SortExpression="username">
<edititemtemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("username") %>'>

<itemtemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("username") %>'>


<asp:TemplateField HeaderText="Status" SortExpression="status">
<edititemtemplate>
<asp:DropDownList ID="DropDownlist1" runat="server" Text='<%# Bind("status") %>'>
<asp:ListItem>Active
<asp:ListItem>Inactive


<itemtemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("status") %>'>


<asp:TemplateField HeaderText="Operations">
<edititemtemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
CommandName="Update" Text="Update">
 <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel">

<itemtemplate>

<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit">
<span önclick="return confirm('Are you sure to Delete this record)')">
 <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete">

</span>



<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SUJAYConnectionString %>"
DeleteCommand="DELETE FROM [admin] WHERE [username] = @username "
InsertCommand="INSERT INTO [admin] ([username], [status]) VALUES (@username, @status)"
SelectCommand="SELECT [username], [status] FROM [admin]"
UpdateCommand="UPDATE [admin] SET [status] = @status WHERE [username] = @username">
<deleteparameters>
<asp:Parameter Name="username" Type="String" />

<insertparameters>
<asp:Parameter Name="username" Type="String" />
<asp:Parameter Name="status" Type="String" />

<updateparameters>
<asp:Parameter Name="status" Type="String" />
<asp:Parameter Name="username" Type="String" />

1 solution

Quote:
As I have used gridview to display datas.In that i m using Dropdownlist. I want answer when I select dropdownlist, I want to delete the whoole row.
Inside the SelectedIndexChanged Event of DropDownList, just get the Primary Key of the current GridViewRow. Find that from the DataSource or Database and delete that.

Now get the Rows again from Database and bind to GridView.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900