|
|
Hello,
I am trying to pass parametarst from one page to another(based on users search) and get results from the database accordingly.
Response.Redirect("~/TestPage.aspx?" + "Test1=" + Server.UrlEncode(comboTest1.Text) + "&Test2=" + Server.UrlEncode(comboTest2.Text));
The user can specify value in the one combo or in the both.
if (Request.QueryString["Test1"] != null || Request.QueryString["Test2"] != null)
{ SelectData(Request.QueryString["Test1"], Request.QueryString["Test2"]); }
DataClassesDataContext db = new DataClassesDataContext();
public IQueryable SelectData(string Test1Query, string Test2)
{
IQueryable data = from t1 in db.Test1
join t2 in db.Test2on t1.ID equals t2.fkTest1 into Joined
from j in Joined.DefaultIfEmpty()
where t1.Manufacturer == Manufacturer || c.Model == Model )
select new { ID = t1.ID, Test1 = t1.Field1, Test2 = j.Field2 };
return data;
}
If the user select only (||) value for the one combo and not the other, the code is not working. How do i fix this? I want the users to be able to perform searches by selecting values from provided number of comboboxes by their own choice.
vasja
|
|
|
|
|
Okay I think I understand what you are asking.
What is wrong with my code why can I get the LINQ to work when the user only selects one and not the other?
Well, I think The problem is the 'if' logic or the 'SelectData' method logic depending how you look at it.
I would make the logic smarter and have values substituted if they are not in range of the query.
-or-
Modify the 'SelectData' method to account for different data dependencies.
~TheArch
|
|
|
|
|
Thank you for your reply. The problem is i get an exception whenever i request the two querystrings and one of them has a null value...
|
|
|
|
|
Correct! You will need to supply either corrective logic, or correct the data values before they are passed.
IE:
MyMethod(String s1, String s2)
{
if(s1 == null)
s1 = '';
if(s2 == null)
s2 = '';
if(s1 == null && s2 == null)
else if(s1 != null && s2 != null)
else if(s1 != null && s2 == null)
else if(s1 == null && s2 != null)
}
as you can see the second method is more complicated. However you could also dynamically build the LINQ query and have the LINQ run correctly for any situation.
~TheArch
|
|
|
|
|
Yes i agree with the
if(s1 == null)
s1 = '';
if(s2 == null)
s2 = '';
but its like 20 values and i tough there is something smarter than this...i would probably use it.
Thanks!
|
|
|
|
|
Well the example only lists the two values.
If there are many values the dynamic LINQ would still do this, just build the query for the values you do have.
Another way to do it might be to change the input to the LINQ method to take an array.
static void myLINQ(String[] s)
{
for(int i=0;i<s.Count;i++)
{
if(s[i] == null)
s[i] = "";
}
}
There are several example here on The Code Project on Dynamic LINQ:
Dynamic LINQ Queries[^]
Google friendly search:
Dynamic LINq c# site:codeproject.com
|
|
|
|
|
Hi,
I was working on a desktop application basically it’s a product now the programming part is over and I have created MSI for this product.
So product and setup both parts are ready but now I have one issue with online updates for this product. I am planning to create a web service for online updates but I would like to know your thoughts as you guys are experienced.
I have used VisualStudio2008, language C# and setup and deployment project.
Please let me know, how to integrate it with setup and deployment project or with programming part or if any other right way for online updates.
Thanks
|
|
|
|
|
Updates should be download automatically from server.Please let me know how to implement it.
|
|
|
|
|
Hi Team,
I want to show one row as bold in my SSRS report. That row is static always but it can change the row no. Ex some times it may come in second sometimes it may come in 5th. but the row is constant always this needs to show in bold
So how to handle this problem
Thanks
|
|
|
|
|
Hi,
What Is the condition? for the row to show as bold..!
Make use of iif Loop ..!
in the expression of the row font..!
way to do it..!
right click on the row go to properties go to font
and write the expression..
check this lnk for expressions
http://msdn.microsoft.com/en-us/library/ms157328.aspx[^]
LatestArticle :Log4Net
Why Do Some People Forget To Mark as Answer .If It Helps.
|
|
|
|
|
|
Its Ok Any Time..!
But Dont forget to mark it as answer if it helps u.!
LatestArticle :Log4Net
Why Do Some People Forget To Mark as Answer .If It Helps.
|
|
|
|
|
Hi all,
If the client borwser is cookies disable then i want to show a message to client plz enable ur cookies.......
for this i am writing this code but it is not working
<script language="javascript" type="text/javascript">
function detect()
{
if(navigator.cookieEnabled)
{
alert('Your browser has cookies enabled.');
}
else
{
alert('Your browser has cookies disabled.');
}
}
</script></head>
<body onload="detect();"></body>
Thanks a lot........
|
|
|
|
|
Just store a cookie and try to retrieve it using javascript. If proper value is retrieved, you will find cookie is enabled.
|
|
|
|
|
Thnks for Replying ........
I am using IE and also block all cookies but
allways answer is ........"cookies found" by fallowing code
if (!IsPostBack)
{
Response.Cookies["test"].Value = "Samar";
Response.Cookies["test"].Expires = DateTime.Now.AddYears(30);
if (Request.Cookies["test"] == null)
Response .Write ("No cookie found");
else
Response .Write ("cookies found");
}
if I used gmail then message is comming that plz enable ur cookies ?
while according previois code it means cookis is creaing ?
then what is exat answer cookies is enable or disable ?
|
|
|
|
|
Did you try redirecting the page, and find cookies from another page ?
Say in your page1 you place :
Response.Cookies["test"] = "Samar";
In page2 you try to retrieve it using :
if(Request.Cookies["test"] == null)
Response.Write("No cookie found");
During the login process, Gmail actually redirects to more than one page before going to actual Gmail Console. So it is easier to them to understand if cookie is actually enabled or not.
I think if you do like this in your login process, you can easily detect this.
|
|
|
|
|
Yes ..........Dear I have done according to you
in first page button clic event I M writng this .....
Response.Cookies["test"].Value = "Samar";
Response.Redirect("Default2.aspx");
and second page form load event
if (Request.Cookies["test"] == null)
Response.Write("No cookie found");
else
Response.Write("cookie found");
I have disabled the cookie but it is still showing "Cookies found"
Note-- I M using IE.
|
|
|
|
|
I think this means cookie is not disabled properly in your browser. If the cookie could be read, then browser didnt prevent it to store cookie properly.
Also try in other browser and try publishing the application in IIS.
|
|
|
|
|
Yes it is Working in Mozilla but not in IE6
How can we check it IE6.........Thnks.......
|
|
|
|
|
try this one
Request.Browser.Cookies
|
|
|
|
|
I thing it is for ur borwser supports cookies or not but not for cookies enable or disable
|
|
|
|
|
I dont know.. But if you can still access the data with Cookies disabled, I think this would be the problem of security in the browser itself which allows the server to read cookies, even if it is disabled.
I think it is always better not to rely on data in Cookies. I wonder how the client browser behaves and even clients can delete cookies any time.
|
|
|
|
|
my Page contain a gridview with a sqldatasource that have a parameter programatically set value
after sqldatasource run a select statement to bind data
i need to have a selectedindex of row for select button
but it gets me error of index out of range
I have done checking..
it seems to me that this gridview get the selectedindex value after twice postback
let say i click on index 1
another click on index 2
the result is selectedindex = 1
that's the problem
|
|
|
|
|
Index for Datagrid starts from 0.
Put your code here so you can get more help.
Rock Star
|
|
|
|