Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i try to call dropdownlist1 but this is not available in list

i try to do something this like this

function is in static
C#
[WebMethod]
       public static string Jqufunc(int yearP,int )
       {


What I have tried:

C#
if ((Dropdownlist1.selectvalue) != 0)
                {
                    con = con.Where(c => c.CustName.Contains(Dropdownlist1.selectvalue) || c.InvoiceID == Dropdownlist1.selectvalue);
                }


but Dropdownlist1 is not in list
<asp:DropDownList ID="DropDownList1" runat="server"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
Posted
Updated 17-May-16 21:16pm
v3
Comments
Raje_ 18-May-16 2:57am    
You have done typo mistake. See your ID is "DropDownList1" and your codebehind code is "Dropdownlist1". Focus on d.

Static methods cannot access non-static class information, which means that any controls which are part of the form are unavailable within your method.
Static methods do not have a this which refers to the current instance of the class - that's what static means, it isn't dependant on any particular instance but general to the whole class - and so can't access anything which does.

If you like, it's like a car: an instance of a car has a colour: because you can't say "what colour is a car?" but you have to specify which car "what colour is this car?", "what colour is that car?", "what colour is my car?" and so forth. "Colour" is an instance property of a car.
But all cars have four wheels, so you can say "how many wheels has a car?" without having to specify a particular instance. "WheelCount" is a static property of a car.

In your case, you could make the method non-static, or pass the control to it from the instance. You can't access any control directly.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900