Hi all,
Sorry again in advance for what is assuredly a 'noob' question. I have as some would know, modified Michael washingtons Tradingpost example on building a module, however one of my modifications required a shift from a gridview with builtin delete etc to a datalist.
Thus far i have wired up a command button and a function, however my object datasource's delete funtion requires my class, and then executes my delete stored proceedure, passing the ID of the chosen ?entry? in my class. However, without the builtin gridview delete option firing off the right information automatically, i'm naturally stumped as to how to achieve this from the codebehind, as always - here is my code!:
I have highlighted in yellow the section i am assuming i need to work on, i have no idea how to make the delete() feed the right item, the commented line was a failed attempt based on some online articles. again many thanks for helping me out!
my Controller.cs:
[DataObjectMethod(DataObjectMethodType.Delete)]
public static void Fileman_Delete(FilemanInfo FilemanInfo)
{
DataProvider.Instance().ExecuteNonQuery("Fileman_Delete", FilemanInfo.ID);
}
------------------------------------------------------------------------------------------------
my codebehind function fired by clicking my "delete button" within an item of the datalist:
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
string cmd = ((Button)e.CommandSource).CommandName;
int cma = System.Convert.ToInt16(e.CommandArgument);
if (cmd == "delete")
{
//ObjectDataSource_Fileman.DeleteParameters["DelID"].DefaultValue = cma.ToString();
ObjectDataSource_Fileman.Delete();
messagebox.Text = cmd + cma + "deletion was attempted... but why no delete AND no error";
}
}
------------------------------------------------------
chunk of my aspx representing part of the datalist itemtemplate:
<asp:DataList ID="DataList1" runat="server" DataSourceID="ObjectDataSource_Fileman" OnItemCommand="DataList1_ItemCommand" DataKeyField="ID">
<ItemTemplate>
<table>
<tr>
<td colspan="2">
<asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>'></asp:Label>
</td>
</tr>
<tr>
<td rowspan="2">
<asp:Image ID="Image1" runat="server" ImageUrl='<%# "./Pictures/" + Eval("Logo") %>' Width="110px" />
</td>
<td width="400">
<asp:Label ID="NotesLabel" runat="server" Text='<%# Eval("Notes") %>'></asp:Label></td>
</tr>
<tr>
<td>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ObjectDataSource_FilemanFiles" OnRowDataBound="HideEditButtons"
Visible="False" Width="100px">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
<asp:BoundField DataField="PDF_ID" HeaderText="PDF_ID" SortExpression="PDF_ID" />
<asp:BoundField DataField="File_title" HeaderText="File_title" SortExpression="File_title" >
<ItemStyle Width="290px" />
</asp:BoundField>
<asp:BoundField DataField="File_loc" HeaderText="File_loc" SortExpression="File_loc" >
<ItemStyle BackColor="#C0FFFF" BorderColor="#00C0C0" BorderStyle="Solid" BorderWidth="1px"
Font-Bold="True" Width="90px" />
</asp:BoundField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
<asp:Button ID="AddFileButton" runat="server" Text="Add File" CommandArgument='<%# Eval("ID") %>' CommandName="addfile" />
<asp:Button ID="DeleteBlockButton" runat="server" Text="Delete Block" CommandArgument='<%# Eval("ID") %>' CommandName="delete" /><br />
<hr />
</ItemTemplate>