Updating asp:SqlDataSource Parameter via asp:LinkButton

Posted by Mattec on Stack Overflow See other posts from Stack Overflow or by Mattec
Published on 2010-04-10T21:28:45Z Indexed on 2010/04/10 21:33 UTC
Read the original article Hit count: 510

Filed under:
|
|
|

I'll try to explain what I'm doing the best I can, but I'm pretty new to asp.net so be patient with me.

I have a SqlDataSource which returns a simple select statement based on the WHERE clause using @COURSE_ID

What I want to-do is every time any one of 2 (this will change as it's going to be generated) asp:LinkButtons are pressed, they will change the @COURSEID value which i'd like to associate with the specific button.

Buttons:

<asp:LinkButton ID="LinkButton2" runat="server" onclick="MenuUpdate_Click">Course1</asp:LinkButton>
 <asp:LinkButton ID="LinkButton1" runat="server" onclick="MenuUpdate_Click">Course2</asp:LinkButton>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:connString %>" SelectCommand="SELECT Chapter.chapterName, Chapter.chapterID

FROM Chapter WHERE Chapter.courseID = @COURSE_ID ">

C# protected void MenuUpdate_Click(object sender, EventArgs e) {

    Parameter p = SqlDataSource1.SelectParameters["COURSE_ID"];
    SqlDataSource1.SelectParameters.Remove(p);
    SqlDataSource1.SelectParameters.Add("COURSE_ID", THIS NEEDS TO BE VALUE ASSOCIATED TO BUTTON);
    ListView1.DataBind();
    UpdatePanel1.Update();

}

If anyone has any suggestions that'd be great, I've been trying lots of different things all night with no success :(

Thanks

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about c#