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!

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">
</asp:SqlDataSource>

Query in the Stored Procedure

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

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
http://aspnet.4guysfromrolla.com/articles/070908-1.aspx

Let me know if you have any more issues.

Thanks,
Chithra

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.