sqldatasource problem
i have a listview with an sqldatasource and the link buttons don't get fired up, but if i use as datasource an String array they get fired up. Am i missing something in my code?
aspx page:
<%
SqlDataSourceArticoleUser.ConnectionString = conn;
SqlDataSourceArticoleUser.SelectCommand = "SELECT top 10 * FROM (SELECT ROW_NUMBER() OVER (ORDER BY id desc) AS Row, * FROM articole) AS EMP WHERE Row >" + pag + " and username='" + user + "'";
%>
<asp:ListView ID="ListViewArticoleUser" runat="server" DataSourceID="SqlDataSourceArticoleUser">
<LayoutTemplate>
<ul>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</ul>
</LayoutTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButtonEditArticolEdit" runat="server" Text="edit" CommandName="articoledit"></asp:LinkButton>
<asp:LinkButton ID="LinkButtonStergeArticolEdit" runat="server" Text="sterge" CommandName="articolsterge"></asp:Lin开发者_开发知识库kButton>
</ItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSourceArticoleUser" runat="server"></asp:SqlDataSource>
aspx.cs page:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SqlDataSourceArticoleUser.DataBind();
}
}
protected void Page_Init(object sender, EventArgs e)
{
ListViewArticoleUser.ItemCommand += new EventHandler<ListViewCommandEventArgs>(ListViewArticoleUser_EventHandler);
}
protected void ListViewArticoleUser_EventHandler(object sender, ListViewCommandEventArgs e)
{
if (e.CommandName == "articolsterge")
{
}
}
I think you are missing something... When you use a string array as datasource, you will use the default c# dataadapter, that contains instructions for delete, update and insert.
When you are working with an sql datasource, you must configure how .net will deal with those operations. I can see you just configured the select operation. To have a full functional sqldatasource, I think you must fill other operations.
Check this article to help you with your datasource: http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/sqldatasource.aspx!
Specially this part:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Pubs %>"
SelectCommand="SELECT [au_id], [au_lname], [au_fname], [state] FROM [authors]"
UpdateCommand="UPDATE [authors] SET [au_id] = @au_id, [au_lname] = @au_lname,[au_fname] = @au_fname, [state] = @state WHERE [au_id] = @original_au_id"
DeleteCommand="DELETE FROM [authors] WHERE [au_id] = @original_au_id"/>
精彩评论