I'm big on doing the majority of my applications in code behind, even GridViews I try to do almost entirely in code where I can. One problem I keep running into with SubSonic3 is being able to define a variable then create a if or case and assign a value to that variable inside the various blocks of code, then assign that variable as the datasource on a gridview, or similar object, so I only have to use one variable for my datasource once the checks have all been done in the if or case. For example:
string myvar = null; //(pick your variable type, string, int, etc)
if(something == "blah")
{
myvar = "select * from table";
}
else if(something == "blah 2")
{
myvar = select * from table2";
}
myGv.DataSource = myvar;
myGv.DataBind();
I run into a problem when I try to do that with using a var type, which all the examples of SubSonic use for linq queries. How can this be done? Or can it at all? The only other way I have to do what I want is to do all the binding code within the if blocks, but in doing that I'm duplicating code. I'm hoping it's something simple that I'm just missing. Thanks for your time!
Jon