List Info

Thread: Re: multiple sqldatasources and one gridview




Re: multiple sqldatasources and one gridview
country flaguser name
United States
2007-06-05 10:29:12



Hello Dean
Thanks for your help, I tried your idea to make one working and then used
the same for all of them
now it is working, cheers
many thanks

>From: "Dean Fiala"; < dfiala%40gmail.com">dfialagmail.com>
>;Reply-To: AspNetAnyQuestionIsOk%40yahoogroups.com">AspNetAnyQuestionIsOkyahoogroups.com
&gt;To: AspNetAnyQuestionIsOk%40yahoogroups.com">AspNetAnyQuestionIsOkyahoogroups.com
&gt;Subject: Re: [AspNetAnyQuestionIsOk] multiple sqldatasources and one
>gridview
>;Date: Tue, 5 Jun 2007 10:36:10 -0400
&gt;
>Three suggestions....
&gt;
>1) create a simple page with one datasource and get that working
>
>2) replace your switch statement with this
>;
>GridView1.Enabled = true;
&gt;GridView1.DataSourceID = String.Format("SqlDataSourceOP&quot;, GotoCase);
>GridView1.DataBind();
&gt;GridView1.Visible = true;
&gt;
>can't tell what your page looks like, but you also might want to try
>this...
>
>SQLDataSourceControl = Page.FindControl(
>String.Format("SqlDataSourceOP",
>GotoCase));
&gt;GridView1.Enabled = true;
&gt;GridView1.DataSourceID =SQLDataSourceControl.ID;
>;GridView1.DataBind();
>GridView1.Visible = true;
&gt;
>
>On 6/5/07, Creative Designer < owaiz_vaiyani%40hotmail.com">owaiz_vaiyanihotmail.com> wrote:
&gt; >
>; >
>; >
>; > the sqldatasource controls are working fine
>; >
>; > i am pasting codebehind page code below
&gt; >
>; > using System;
> > using System.Data;
> > using System.Configuration;
> > using System.Collections;
> > using System.Web;
> > using System.Web.Security;
> > using System.Web.UI;
> > using System.Web.UI.WebControls;
&gt; > using System.Web.UI.WebControls.WebParts;
>; > using System.Web.UI.HtmlControls;
&gt; >
>; > public partial class SysAdmin_SearchCustomer : System.Web.UI.Page
> > {
> > protected void Page_Load(object sender, EventArgs e)
> > {
> >
>; > }
> >
>; > protected void Button1_Click(object sender, EventArgs e)
> > {
> > String Op1 = SearchOp1.Text;
>; > String Op2 = SearchOp2.Text;
>; > String Op3 = SearchOp3.Text;
>; > String Op4 = SearchOp4.Text;
>; > int GotoCase = 0;
> > if (Op1.Equals("&quot;) && Op2.Equals("&quot;) && Op3.Equals("&quot;) &&
> > Op4.Equals("&quot;))
>; > {
> > Response.Write(";Please Enter Something To Search&quot;);
> > }
> > else
>; > {
> > if (Op1.Length > 0 && Op2.Length > 0 && Op3.Length > 0 &&
> > Op4.Length > 0)
> > {
> > GotoCase = 1;
> >
>; > }
> > else if (Op1.Length > 0 && Op2.Length > 0 && Op3.Length > 0 &&
> > Op4.Length == 0)
> > {
> > GotoCase = 2;
> >
>; > }
> > else if (Op1.Length > 0 && Op2.Length > 0 && Op3.Length == 0 &&
> > Op4.Length == 0)
> > {
> > GotoCase = 3;
> > }
> > else if (Op1.Length > 0 && Op2.Length == 0 && Op3.Length == 0 &&
> > Op4.Length == 0)
> > {
> > GotoCase = 4;
> > }
> > else if (Op1.Length == 0 && Op2.Length > 0 && Op3.Length > 0 &&
> > Op4.Length > 0)
> > {
> > GotoCase = 5;
> > }
> > else if (Op1.Length == 0 && Op2.Length > 0 && Op3.Length > 0 &&
> > Op4.Length == 0)
> > {
> > GotoCase = 6;
> >
>; > }
> > else if (Op1.Length == 0 && Op2.Length > 0 && Op3.Length == 0 &&
> > Op4.Length == 0)
> > {
> > GotoCase = 7;
> > }
> > else if (Op1.Length == 0 && Op2.Length == 0 && Op3.Length > 0 &&
> > Op4.Length > 0)
> > {
> > GotoCase = 8;
> > }
> > else if (Op1.Length == 0 && Op2.Length == 0 && Op3.Length > 0 &&
> > Op4.Length == 0)
> > {
> > GotoCase = 9;
> > }
> > else if (Op1.Length == 0 && Op2.Length == 0 && Op3.Length == 0
> > && Op4.Length > 0)
> > {
> > GotoCase = 10;
> > }
> > else if (Op1.Length > 0 && Op2.Length == 0 && Op3.Length == 0 &&
> > Op4.Length > 0)
> > {
> > GotoCase = 11;
> > }
> > else if (Op1.Length > 0 && Op2.Length == 0 && Op3.Length > 0 &&
> > Op4.Length == 0)
> > {
> > GotoCase = 12;
> > }
> > else if (Op1.Length == 0 && Op2.Length > 0 && Op3.Length == 0 &&
> > Op4.Length > 0)
> > {
> > GotoCase = 13;
> > }
> > else if (Op1.Length > 0 && Op2.Length == 0 && Op3.Length > 0 &&
> > Op4.Length > 0)
> > {
> > GotoCase = 14;
> > }
> > else if (Op1.Length > 0 && Op2.Length > 0 && Op3.Length == 0 &&
> > Op4.Length > 0)
> > {
> > GotoCase = 15;
> > }
> > else
>; > {
> > GotoCase = 0;
> > }
> > }
> > Response.Write(";Going to Case = " + GotoCase + " ..." + Op1 + Op2 +
> > Op3 + Op4);
&gt; > //Response.Write(&quot;<BR&gt;"3;Op1.Length + Op2.Length + Op3.Length);
> > switch (GotoCase)
> > {
> > case 1:
> > GridView1.Enabled = true;
&gt; > GridView1.DataSourceID = "SqlDataSourceOP1";
> > GridView1.DataBind();
> > GridView1.Visible = true;
&gt; >
>; > break;
&gt; > case 2:
> > GridView1.Enabled = true;
&gt; > GridView1.DataSourceID = "SqlDataSourceOP2";
> > GridView1.DataBind();
> > GridView1.Visible = true;
&gt; >
>; > break;
&gt; > case 3:
> > GridView1.Enabled = true;
&gt; > GridView1.DataSourceID = "SqlDataSourceOP3";
> > GridView1.DataBind();
> > GridView1.Visible = true;
&gt; >
>; > break;
&gt; > case 4:
> > GridView1.Enabled = true;
&gt; > GridView1.DataSourceID = "SqlDataSourceOP4";
> > GridView1.DataBind();
> > GridView1.Visible = true;
&gt; > break;
&gt; > case 5:
> > GridView1.Enabled = true;
&gt; > GridView1.DataSourceID = "SqlDataSourceOP5";
> > GridView1.DataBind();
> > GridView1.Visible = true;
&gt; > break;
&gt; > case 6:
> > GridView1.DataSourceID = "SqlDataSourceOP6";
> > GridView1.Enabled = true;
&gt; > GridView1.DataBind();
> > GridView1.Visible = true;
&gt; > break;
&gt; > case 7:
> > GridView1.Enabled = true;
&gt; > GridView1.DataSourceID = "SqlDataSourceOP7";
> > GridView1.DataBind();
> > GridView1.Visible = true;
&gt; > break;
&gt; > case 8:
> > GridView1.Enabled = true;
&gt; > GridView1.DataSourceID = "SqlDataSourceOp8";
> > GridView1.DataBind();
> > GridView1.Visible = true;
&gt; > break;
&gt; > case 9:
> >
>; > GridView1.Enabled = true;
&gt; > GridView1.DataSourceID = "SqlDataSourceOp9";
> > GridView1.DataBind();
> > GridView1.Visible = true;
&gt; > break;
&gt; > case 10:
> > GridView1.Visible = true;
&gt; > GridView1.DataSourceID = "SqlDataSourceOp10";
> > GridView1.DataBind();
> > GridView1.Visible = true;
&gt; > break;
&gt; > case 11:
> > GridView1.Enabled = true;
&gt; > GridView1.DataSourceID = "SqlDataSourceOp11";
> > GridView1.DataBind();
> > GridView1.Visible = true;
&gt; > break;
&gt; > case 12:
> > GridView1.Enabled = true;
&gt; > GridView1.DataSourceID = "SqlDataSourceOp12";
> > GridView1.DataBind();
> > GridView1.Visible = true;
&gt; > break;
&gt; > case 13:
> > GridView1.Enabled = true;
&gt; > GridView1.DataSourceID = "SqlDataSourceOp13";
> > GridView1.DataBind();
> > GridView1.Visible = true;
&gt; > break;
&gt; > case 14:
> > GridView1.Enabled = true;
&gt; > GridView1.DataSourceID = "SqlDataSourceOp14";
> > GridView1.DataBind();
> > GridView1.Visible = true;
&gt; > break;
&gt; > case 15:
> > GridView1.Enabled = true;
&gt; > GridView1.DataSourceID = "SqlDataSourceOp15";
> > GridView1.DataBind();
> > GridView1.Visible = true;
&gt; > break;
&gt; >
>; > case 0:
> > Response.Write(";No Results Found, Try Searching Again";);
> > break;
&gt; >
>; > }
> > Response.Write(";Gridview " + GridView1.DataSourceID + "<BR> Count
&gt; > "+;GridView1.Columns.Count);
&gt; > }
> > }
> >
>; > >From: "Dean Fiala"; < dfiala%40gmail.com">dfialagmail.com <dfiala%40gmail.com>>
> > >Reply-To:
> AspNetAnyQuestionIsOk%40yahoogroups.com">AspNetAnyQuestionIsOkyahoogroups.com<AspNetAnyQuestionIsOk%40yahoogroups.com>;
> > >To:
> AspNetAnyQuestionIsOk%40yahoogroups.com">AspNetAnyQuestionIsOkyahoogroups.com<AspNetAnyQuestionIsOk%40yahoogroups.com>;
> > >Subject: Re: [AspNetAnyQuestionIsOk] multiple sqldatasources and one
> > >gridview
> > >Date: Tue, 5 Jun 2007 09:33:09 -0400
&gt; > >
>; > >Trace your code, make sure it is following the proper path.
&gt; > >
>; > >Are you calling .DataBind() for all your GridViews?
> > >
>; > >Are the data sources set up properly?
> > >
>; > >Assuming the DataSources are set up properly setting the DataSourceID
>and
> > >binding are all you have to do.
> > >
>; > >You're the only one with all the code in front of you. The rest of us
>can
> > >only guess what's going on
> > >
>; > >On 6/5/07, Creative Designer
><; owaiz_vaiyani%40hotmail.com">owaiz_vaiyanihotmail.com<owaiz_vaiyani%40hotmail.com>>
> > wrote:
&gt; > > >
>; > > > nop
> > > > that didnt work either
&gt; > > > gridview does not come up
> > > >
>; > > > >From: "Dean Fiala"; < dfiala%40gmail.com">dfialagmail.com
><;dfiala%40gmail.com&gt;<dfiala%40gmail.com>>;
> > > > >Reply-To:
> >
> > AspNetAnyQuestionIsOk%40yahoogroups.com">AspNetAnyQuestionIsOkyahoogroups.com<AspNetAnyQuestionIsOk%40yahoogroups.com>;
> > <AspNetAnyQuestionIsOk%40yahoogroups.com>
&gt; > > > >To:
> >
> > AspNetAnyQuestionIsOk%40yahoogroups.com">AspNetAnyQuestionIsOkyahoogroups.com<AspNetAnyQuestionIsOk%40yahoogroups.com>;
> > <AspNetAnyQuestionIsOk%40yahoogroups.com>
&gt; > > > >Subject: Re: [AspNetAnyQuestionIsOk] multiple sqldatasources and
>one
> > > > >gridview
> > > > >Date: Tue, 5 Jun 2007 09:08:20 -0400
&gt; > > > >
>; > > > > GridView1.DataBind();
> > > > >
>; > > > >On 6/5/07, Creative Designer
> > >< owaiz_vaiyani%40hotmail.com">owaiz_vaiyanihotmail.com <owaiz_vaiyani%40hotmail.com>
>; > <owaiz_vaiyani%40hotmail.com>>
> > > > wrote:
&gt; > > > > >
>; > > > > >
>; > > > > >
>; > > > > > thanks again
&gt; > > > > > but it does not work, still nothing comesup
> > > > > > here is my code
>; > > > > >
>; > > > > > case 1:
> > > > > > GridView1.DataSourceID = "SqlDataSourceOP1";
> > > > > > GridView1.Enabled = true;
&gt; > > > > > GridView1.Visible = true;
&gt; > > > > >
>; > > > > > break;
&gt; > > > > > case 2:
> > > > > > GridView1.DataSourceID = "SqlDataSourceOP2";
> > > > > > GridView1.Enabled = true;
&gt; > > > > > GridView1.Visible = true;
&gt; > > > > >
>; > > > > > break;
&gt; > > > > > etc..
&gt; > > > > >
>; > > > > > >From: "Dean Fiala"; < dfiala%40gmail.com">dfialagmail.com <dfiala%40gmail.com>
&gt; > ><dfiala%40gmail.com>&lt;dfiala%40gmail.com>>
> > > > > > >Reply-To:
> > > >
>; > >
> > AspNetAnyQuestionIsOk%40yahoogroups.com">AspNetAnyQuestionIsOkyahoogroups.com<AspNetAnyQuestionIsOk%40yahoogroups.com>;
> > <AspNetAnyQuestionIsOk%40yahoogroups.com>
&gt; > > > <AspNetAnyQuestionIsOk%40yahoogroups.com>
&gt; > > > > > >To:
> > > >
>; > >
> > AspNetAnyQuestionIsOk%40yahoogroups.com">AspNetAnyQuestionIsOkyahoogroups.com<AspNetAnyQuestionIsOk%40yahoogroups.com>;
> > <AspNetAnyQuestionIsOk%40yahoogroups.com>
&gt; > > > <AspNetAnyQuestionIsOk%40yahoogroups.com>
&gt; > > > > > >Subject: Re: [AspNetAnyQuestionIsOk] multiple sqldatasources
>and
> > >one
> > > > > > >gridview
> > > > > > >Date: Tue, 5 Jun 2007 08:38:53 -0400
&gt; > > > > > >
>; > > > > > > GridView1.DataSourceID = "SqlDataSourceOP1";
> > > > > > >
>; > > > > > >On 6/5/07, Creative Designer
> > > > >< owaiz_vaiyani%40hotmail.com">owaiz_vaiyanihotmail.com
><;owaiz_vaiyani%40hotmail.com>;<owaiz_vaiyani%40hotmail.com>
>; > > > <owaiz_vaiyani%40hotmail.com>>
> > > > > > wrote:
&gt; > > > > > > >
>; > > > > > > >
>; > > > > > > >
>; > > > > > > > hi dean
>; > > > > > > > thanks for your reply
&gt; > > > > > > > i have tried
&gt; > > > > > > > GridView1.DataSourceID = SqlDataSourceOP1;
&gt; > > > > > > >
>; > > > > > > > but it comes out with this error.
&gt; > > > > > > >
>; > > > > > > > CS0029: Cannot implicitly convert type
>; > > > > > > > 'System.Web.UI.WebControls.SqlDataSource' to 'string'
> > > > > > > >
>; > > > > > > > I have also tried
&gt; > > > > > > > GridView1.DataSourceID = SqlDataSourceOP1.UniqueID;
&gt; > > > > > > >
>; > > > > > > > which does not give any error however does not return any
> > >result.
> > > > > > > > i am sure my control is working coz i have tried the query
>in
> > > > query
&gt; > > > > > > > buil;der.
> > > > > > > >
>; > > > > > > > thanks
&gt; > > > > > > >
>; > > > > > > > >From: "Dean Fiala"; < dfiala%40gmail.com">dfialagmail.com
><;dfiala%40gmail.com&gt;<dfiala%40gmail.com>
&gt; > > > ><dfiala%40gmail.com>&lt;dfiala%40gmail.com>>
> > > > > > > > >Reply-To:
> > > > > >
>; > > > >
>; > >
> > AspNetAnyQuestionIsOk%40yahoogroups.com">AspNetAnyQuestionIsOkyahoogroups.com<AspNetAnyQuestionIsOk%40yahoogroups.com>;
> > <AspNetAnyQuestionIsOk%40yahoogroups.com>
&gt; > > > <AspNetAnyQuestionIsOk%40yahoogroups.com>
&gt; > > > > > <AspNetAnyQuestionIsOk%40yahoogroups.com>
&gt; > > > > > > > >To:
> > > > > >
>; > > > >
>; > >
> > AspNetAnyQuestionIsOk%40yahoogroups.com">AspNetAnyQuestionIsOkyahoogroups.com<AspNetAnyQuestionIsOk%40yahoogroups.com>;
> > <AspNetAnyQuestionIsOk%40yahoogroups.com>
&gt; > > > <AspNetAnyQuestionIsOk%40yahoogroups.com>
&gt; >
>; > > > > > <AspNetAnyQuestionIsOk%40yahoogroups.com>
&gt; > > >
>; > > > > > > > >Subject: Re: [AspNetAnyQuestionIsOk] multiple
>sqldatasources
> > >and
> > > > >one
> > > > > > > > >gridview
> > > > > > > > >Date: Tue, 15 May 2007 08:39:26 -0400
&gt; > > > > > > > >
>; > > > > > > > >If you have defined data source controls, you just need to
> > set
> > > > the
> > > > > > > > >DataSourceID
&gt; > > > > > > > >
>; > > > > > > > >gridview1.DataSourceID = sqldatasource1;
>; > > > > > > > >
>; > > > > > > > >
>; > > > > > > >
>; > > > > > >
>; > > > > >
>; > > > >
>; > > >
>; > >
>; >
>http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.databoundcontrol.datasourceid.aspx
> > > > > > > > >
>; > > > > > > > >
>; > > > > > > > >On 5/15/07, Creative Designer
> > > > > > >< owaiz_vaiyani%40hotmail.com">owaiz_vaiyanihotmail.com <owaiz_vaiyani%40hotmail.com>
>; > ><owaiz_vaiyani%40hotmail.com>&lt;owaiz_vaiyani%40hotmail.com&gt;
> > > > > > <owaiz_vaiyani%40hotmail.com>>
> > > > > >
>; > > > > > > > wrote:
&gt; > > > > > > > > >
>; > > > > > > > > > Hello
&gt; > > > > > > > > >
>; > > > > > > > > > I like to know how to assign datasource for a gridview
> > >behind
> > > > >code
> > > > > > > > page.
&gt; > > > > > > > > >
>; > > > > > > > > > I have created multiple sqldatasources and one gridview,
> > > > >depending
> > > > > >
>; > > > > > >on
&gt; > > > > > > > > > input
&gt; > > > > > > > > > from user, the gridview will select one of those
&gt; > datasources
> > > > > > > > > >
>; > > > > > > > > > i have tried doing this with no result
&gt; > > > > > > > > >
>; > > > > > > > > > gridview1.datasource = sqldatasource1;
>; > > > > > > > > >
>; > > > > > > > > > gridview.databind();
> > > > > > > > > >
>; > > > > > > > > > please help/ thnks
&gt; > > > > > > > > >
>; > > > > > > > > >
>__________________________________________________________
&gt; > > > > > > > > > Could you be the guest MSN Movies presenter? Click Here
>to
> > > > > > Audition
> > > > > > > > > > http://www.lightscameraaudition.co.uk
> > > > > > > > > >
>; > > > > > > > > >
>; > > > > > > > > >
>; > > > > > > > >
>; > > > > > > > >
>; > > > > > > > >
>; > > > > > > > >--
&gt; > > > > > > > >Dean Fiala
&gt; > > > > > > > >Very Practical Software, Inc
> > > > > > > > >Now with Blogging...
> > > > > > > > >http://www.vpsw.com/blogbaby
> > > > > > > > >Microsoft MVP
> > > > > > > > >
>; > > > > > > > >
>; > > > > > > > >[Non-text portions of this message have been removed]
> > > > > > > > >
>; > > > > > > >
>; > > > > > > > __________________________________________________________
> > > > > > > > The next generation of Hotmail is here!
&gt; > > > http://www.newhotmail.co.uk/
> > > > > > > >
>; > > > > > > >
>; > > > > > > >
>; > > > > > >
>; > > > > > >
>; > > > > > >
>; > > > > > >--
&gt; > > > > > >Dean Fiala
&gt; > > > > > >Very Practical Software, Inc
> > > > > > >Now with Blogging...
> > > > > > >http://www.vpsw.com/blogbaby
> > > > > > >Microsoft MVP
> > > > > > >
>; > > > > > >
>; > > > > > >[Non-text portions of this message have been removed]
> > > > > > >
>; > > > > >
>; > > > > > __________________________________________________________
> > > > > > Could you be the guest MSN Movies presenter? Click Here to
> > Audition
> > > > > > http://www.lightscameraaudition.co.uk
> > > > > >
>; > > > > >
>; > > > > >
>; > > > >
>; > > > >
>; > > > >
>; > > > >--
&gt; > > > >Dean Fiala
&gt; > > > >Very Practical Software, Inc
> > > > >Now with Blogging...
> > > > >http://www.vpsw.com/blogbaby
> > > > >Microsoft MVP
> > > > >
>; > > > >
>; > > > >[Non-text portions of this message have been removed]
> > > > >
>; > > >
>; > > > __________________________________________________________
> > > > Play your part in making history - Email Britain!
> > > > http://www.emailbritain.co.uk/
> > > >
>; > > >
>; > > >
>; > >
>; > >
>; > >
>; > >--
&gt; > >Dean Fiala
&gt; > >Very Practical Software, Inc
> > >Now with Blogging...
> > >http://www.vpsw.com/blogbaby
> > >Microsoft MVP
> > >
>; > >
>; > >[Non-text portions of this message have been removed]
> > >
>; >
>; > __________________________________________________________
> > The next generation of Hotmail is here! http://www.newhotmail.co.uk
> >
>; >
>; >
>;
>
>
>--
>Dean Fiala
&gt;Very Practical Software, Inc
>Now with Blogging...
>http://www.vpsw.com/blogbaby
>Microsoft MVP
>
>
&gt;[Non-text portions of this message have been removed]
>

__________________________________________________________
Could you be the guest MSN Movies presenter? Click Here to Audition
http://www.lightscameraaudition.co.uk

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )