I have this code, that i found on this website
<asp:DataList runat="server" ID="Datalist1" DataSourceID="SqlDataSource1" DataKeyField="BrandID" OnDeleteCommand="DataList1_DeleteCommand">
<ItemTemplate>
<asp:Label runat="server" ID="BrandNameLabel" Text='<%#Eval("BrandName") %>' />
<br/>
<asp:Button runat="server" ID="Delete" Text="Slet" CommandName="Delete" />
</ItemTemplate>
</asp:DataList>
protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e)
{
int id = (int) Datalist1.DataKeys[e.Item.ItemIndex];
SqlDataSource1.DeleteParameters["BrandID"].DefaultValue = id;
SqlDataSource1.Delete();
}
I think I have made it like the website, but i get and error called “Cannot convert source type ‘int’ to target type ‘string'”
My BrandID is and int.
Can you please help me, and show how I convert it.
DefaultValue is a string. You can simply do this: