Calling a Sub / Error Message

JohnH

New Member
Hi all,<BR><BR>I want to call a subroutine on loading of the page. Here is the code:<BR><BR>Sub Page_Load(Sender As Object, E As EventArgs)<BR> If NOT Page.IsPostBack Then<BR> BindSport<BR> End If<BR>End Sub<BR><BR>Sub BindSport(Sender As Object, E As EventArgs)<BR>...Code that binds some data to DataGrid<BR>End Sub<BR><BR>Here is the error message I get:<BR>Compiler Error Message: BC30455: Argument not specified for parameter 'E' of 'Public Sub BindSport(Sender As Object, E As System.EventArgs)'.<BR><BR>Can someone tell me what the problem is?<BR><BR>Thanks,<BR>D.change to this:<BR>----------------------------------------------<BR>Sub BindSport() <BR>...Code that binds some data to DataGrid <BR>End Sub <BR>----------------------------------------------<BR><BR>Your sub is expecting parameters and you are not passing any.....The sub is used elsewhere in the code where parameters are passed. Is there a way to make EventArgs optional?Well, i don't think you need those parameters in your bindsport unless it is a system defined events. But if you want to use them, i think your problem may be that you might not have declared the function with protected events at the top, since you are using event args.<BR>I think(but not positive) that you will need:<BR>Protected WithEvents grdStaffGrid As System.Web.UI.WebControls.DataGrid<BR>(This is one for my DataGrid)<BR><BR>But, on second thought, i think you may not need those parameters at all. I looked through the system.something lists and couln't really find an appropriate one. I could be worng though.<BR><BR>Let me know what happens, i'll keep looking :)<BR>The BindSport subroutine is called on the SelectedIndexChanged event of a DropDownList. It populates a DataGrid based on the returned value. However, when the page loads, I want the DataGrid to load all sports. I don't see a reason why the same sub can't be used since all I am doing is checking if a parameter has been passed or not then populating the DG. But alas, I get that error message when I try and call BindSport in the Page_Load event. I'm relatively new to .NET, so my entire approach may be wrong. Seems logical to me though.Hmm.. Well, which event args are you using? Because I am under the impression that those parameters are only for system functions and refernces.<BR>This may not be a solution, cause there are like a bunch of things I would try.<BR>One thing would be to try to take out those parameters and put your own in. If you want to load all data on page load, pass a parameter like 0 or something you know you will never use for the grid and then do an "If Then Else" to bind the grid.<BR>ie:<BR>Sub BindSport(byVal SomeValue As String) ' Or whatever you want it to be<BR>.....<BR>If SomeValue = http://aspmessageboard.com/archive/index.php/0 Then<BR> sqlStatement = "select * from Sports"<BR>Else<BR> sqlStatement = "select * form Sports where Value = '" & VariableYouPassed & "'"<BR>End If<BR>.....<BR>End Sub<BR><BR>I've used this to bind all or just selected stuff for grid and list boxes.<BR>I'm not sure if this may help. Let me know :) Good Luck!
 
Back
Top