views:

180

answers:

1

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

A: 

Hey Matt,

Try setting the linkbutton IDs to contain the course name (I dont think its possible for IDs to start with numbers, so give them IDs "crs" and then the course name). In the click event for the buttons, extract the ID of the sender and take the entire string after "crs". This is the course name of the linkbutton that was clicked.

Also if "COURSE_ID" is the only parameter of the SelectCommand, I would personally clear all the parameters first. It just ensures that you dont have any parameters from elsewhere. Thats just the way I work though - clear everything and reenter anything which shouldnt have been cleared and then enter anything extra.

Regards,

Rich

ClarkeyBoy
Thanks Rich, I'll give it a crack in the morning and let you know how I got on.
Mattec
One other thing - I am not sure if you need to call "SqlDataSource1.Select()" too.. it might be that the ListView does this itself, but ive never used one so have no idea..
ClarkeyBoy
You can better use the TagName instead of id
Veer
By the way the point about starting the IDs with a set string (in this case "crs" may not seem relevant if the course names are always going to start with a letter.. its just a precaution that I always take to ensure the ID is valid if I am basing IDs on values taken from a database as they could potentially start with a symbol or number. Something else I just thought of - replace symbols as some symbols are not allowed in an ID. You can use a regular expression for this - theres lots of tutorials about those..Regards,Rich
ClarkeyBoy