Dropdown menu+select+Delete+Asp.net+vb

Posted by Baijuep under Regular Expressions on 3/20/2011 | Points: 10 | Views : 1421 | Status : [Member] | Replies : 2
i have a dropdownmenu which collects data from a sql table and a delete button
i want to delete the data whiich is selected by the dropdown menu

Baiju EP


Responses

Posted by: Karthikanbarasan on: 3/20/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Try the below code

<asp:DropDownList ID="ddlDelete" runat="server" DataSourceID="SqlDataSource2" DataTextField="id" DataValueField="id">


</asp:DropDownList>

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id"
DataSourceID="SqlDataSource1">
<Columns>

<asp:CommandField ShowDeleteButton="True" />

<asp:BoundField DataField="link" HeaderText="link" SortExpression="link" />
<asp:BoundField DataField="img" HeaderText="img" SortExpression="img" />
</Columns>
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:mytest1ConnectionString %>"
SelectCommand="SELECT [id], [link], [img] FROM [images]"
DeleteCommand="Delete FROM [images] WHERE id=@id" >

<DeleteParameters> <asp:ControlParameter ControlID="ddlDelete" Name="id" PropertyName="SelectedValue" Type="Int32" />
</DeleteParameters>
</asp:SqlDataSource>


<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:mytest1ConnectionString %>"
SelectCommand="SELECT [id] FROM [images]" >
</asp:SqlDataSource>


Thanks
Karthik
www.f5Debug.net

Baijuep, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 3/20/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Check this MSDN article as well

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.delete.aspx

Thanks
Karthik
www.f5Debug.net

Baijuep, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response