Alright, so right now I have a GridView on my aspx page. It is set to run a stored procedure, get some data and display it. The parameter for the stored proc is set to come in through a query string. So the sqldatasource atuomatically looks for a query string called arg and and uses that as the parameter.

I want to pass more than one value, dynamicly determined, to the sqldatasource. Is this possable? Like give it a bunch of variables to look for and run the procedure with each one?

I suppose I could make a gridview and sqldatasource for each possable value, and each datasource will look for it's own query string. But that seems kinda like the wrong way to do it.

Any ideas? or is this asking for aspx to do too much work for me?

Thanks in advance for any help!

9 Years
Discussion Span
Last Post by chithrasujith

I couldnot understand your question entirely. See if this is what you wanted to know.

In my example I have a GridView which gets data from a SQLDataSource(StoredProcedure).

I will pass a username through QueryString, and the GridView would print the Username and the count of that username.

Now I want to give a ‘bunch of usernames’ and I need the count(*) against each username.

You can programmatically do that on the Page_Load Method like below.

protected void Page_Load(object sender, EventArgs e)
	string usernameList = “alex,christine”;
SqlDataSource1.SelectParameters.Add("usernames", usernameList);         

You can use a for loop to get the dyanmic number of usernames into the String usernameList and pass it to the SqlDataSource(StoredProcedure).

The SQLDataSource

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:LoginsConnectionString %>"
            SelectCommand="StoredProcedure1" SelectCommandType="StoredProcedure">

Query in the Stored Procedure

ALTER PROCEDURE dbo.StoredProcedure1 @usernames nchar(10)
select username,count(*) from Login where  username IN (SELECT Value FROM dbo.Function1 ( @usernames, ',') ) group by username

The reasone we have used a custom function dbo.Function1 is because StoredProcedure doesnot allow us to give the list of usernames in an argument as below.

select username,count(*) from Login where  username IN (@usernames) group by username

You will get the logic for Function1 from

Let me know if you have any more issues.


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.