D
David
Sorry about all these linq questions I am raising. There is so much about
this that I don't know and am getting frustrated with it. :-(
This has taken me ages to work out... (the structure of this code, just
simply to populate drop down lists)
using (DataClassesDataContext context = new
DataClassesDataContext())
{
var Query = from ct in context.aspnet_Users select ct;
if (Query != null)
{
UsersDropDownList.DataSource = Query.Distinct().ToList();
UsersDropDownList.DataTextField = "UserName";
UsersDropDownList.DataValueField = "UserId";
UsersDropDownList.DataBind();
}
var Query2 = from ct in context.Sections select ct;
if (Query != null)
{
SectionDropDownList.DataSource = Query2.Distinct().ToList();
SectionDropDownList.DataTextField = "SectionName";
SectionDropDownList.DataValueField = "SectionID";
SectionDropDownList.DataBind();
}
}
}
I couldn't re-use the Query variable, so had to create another.
At the moment, I don't know how to combine two fields in the DB... for
example, say I had UserEmpNo and UserName in aspnet_Users, then I want to
display both of those in my drop down. In sql, it would be simple... sql =
"select UserEmpNo + ' : ' + UserName as userDetail from aspnet_Users.
So, in the var Query above, I would need to do something like... (but I
can't have commas)
from ct in context.aspnet_Users select ct.UserEmpNo + ' : ' + UserName as
userDetail, UserId;
Any ideas how I would do this?
Also, if I wanted to use a linked table, say I had aspnet_Membership (which
is linked one to one to aspnet_Users) and then I linked aspnet_Membership
with a one to one to my own userDetails table, how could I get any items out
of my userDetails that relate to the intial aspnet_Users?
Thanks for your help.
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
this that I don't know and am getting frustrated with it. :-(
This has taken me ages to work out... (the structure of this code, just
simply to populate drop down lists)
using (DataClassesDataContext context = new
DataClassesDataContext())
{
var Query = from ct in context.aspnet_Users select ct;
if (Query != null)
{
UsersDropDownList.DataSource = Query.Distinct().ToList();
UsersDropDownList.DataTextField = "UserName";
UsersDropDownList.DataValueField = "UserId";
UsersDropDownList.DataBind();
}
var Query2 = from ct in context.Sections select ct;
if (Query != null)
{
SectionDropDownList.DataSource = Query2.Distinct().ToList();
SectionDropDownList.DataTextField = "SectionName";
SectionDropDownList.DataValueField = "SectionID";
SectionDropDownList.DataBind();
}
}
}
I couldn't re-use the Query variable, so had to create another.
At the moment, I don't know how to combine two fields in the DB... for
example, say I had UserEmpNo and UserName in aspnet_Users, then I want to
display both of those in my drop down. In sql, it would be simple... sql =
"select UserEmpNo + ' : ' + UserName as userDetail from aspnet_Users.
So, in the var Query above, I would need to do something like... (but I
can't have commas)
from ct in context.aspnet_Users select ct.UserEmpNo + ' : ' + UserName as
userDetail, UserId;
Any ideas how I would do this?
Also, if I wanted to use a linked table, say I had aspnet_Membership (which
is linked one to one to aspnet_Users) and then I linked aspnet_Membership
with a one to one to my own userDetails table, how could I get any items out
of my userDetails that relate to the intial aspnet_Users?
Thanks for your help.
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available