2

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:LinkButton>
                </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")
        {
        }
    }
1
  • Also, remind me to register on that site with a user name of: '; delete * from articole; Commented Jan 11, 2011 at 19:23

1 Answer 1

1

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"/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.