Click here to Skip to main content
15,915,087 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello..

here i got Error is
object does not contain a definition for 'CommandArgument' and no extension method 'CommandArgument' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)


can anybody help me please..

C#
public void PagerButtonClick(object sender, CommandEventArgs e)
    //public void PagerButtonClick(object sender, EventArgs e)
    {
        string arg = sender.CommandArgument.ToString();
        //string arg = sender.ToString();
        switch (arg)
        {
            case "next":
                //The next Button was Clicked
                if ((dgcategory.CurrentPageIndex < (dgcategory.PageCount - 1)))
                {
                    dgcategory.CurrentPageIndex += 1;
                }
                break;
            case "prev":
                //The prev button was clicked
                if ((dgcategory.CurrentPageIndex > 0))
                {
                    dgcategory.CurrentPageIndex -= 1;
                }
                break;
            case "last":
                //The Last Page button was clicked
                dgcategory.CurrentPageIndex = (dgcategory.PageCount - 1);
                break;
            default:
                //The First Page button was clicked
                dgcategory.CurrentPageIndex =Convert.ToInt32(arg);
                break;
        }
        //selpagecombo()
        //Now, bind the data!
        BindCategory();
    }



thanks in advance
Posted
Updated 20-May-10 2:32am
v2

instead of:

sender.CommandArgument.ToString();


try using:

e.CommandName;
 
Share this answer
 
Comments
narendrarathod 20-May-10 7:22am    
Thank you for giving me response but e.CommandName also not working..
Gavs43 20-May-10 7:40am    
what control is this (datagrid/gridview)? are you doing some sort of custom pager? if so can you give us more details/code examples?
narendrarathod 20-May-10 8:05am    
yes sure i use linkbuttons for paging onlick =Pagerbuttonclick ,CommandArgument="next" just like

<asp:linkbutton id="PrevButton" onclick="PagerButtonClick" runat="server" cssclass="contant" commandargument="prev">Prev
Gavs43 20-May-10 8:12am    
if this is a gridview you need to use the gridview's event 'onrowcommand'.

Then use

if (e.CommandName =="Page")
{
switch (e.CommandArgument.ToString().ToLower())
{
case "next": //The next Button was Clicked
etc...
Gavs43 20-May-10 8:15am    
oh and if you are using a custom pager you need to add the commandargument and commandname properties to the control ie:

PagerTemplate>
asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="~/images/controls/first.gif"
CommandArgument="First" CommandName="Page" />


See here: CommandEventArgs Constructor[^].

Your code should look something like:

string arg = e.CommandArgument.ToString();
 
Share this answer
 
Comments
narendrarathod 20-May-10 7:17am    
thank you for your response but it is not working.. same error
R. Giskard Reventlov 20-May-10 7:42am    
Same error?
R. Giskard Reventlov 20-May-10 7:50am    
You have actually added a CommandArgument to the object, haven't you?
Actually, does the object actually have CommandEventArgs? If not then just changing the method signature won't help.
Like the other responses have shown, because we don't know what type of object is calling this method, it's hard to diagnose. If you are using CommandEventArgs, it has a CommandArgument property that should be set. If, however, you're calling this yourself and passing null as the CommandEventArgs, then you will get an error.

If the object (ie sender) has a CommandArgument, then you need to case sender before calling it to the type that it is. object is a base class and does not contain CommandArgument, which is what the error is telling you.

For instance, if this was a RichTextBox and we were handling the TextChanged event, we could use
C#
string RTF = (RichTextBox)sender.Rtf;

but we would get the same error you got if we tried
C#
string RTF = sender.Rtf;


What kind of object is calling this method? Is this a Button from the System.Web.UI.WebControls class? If so, try:
C#
string arg = (System.Web.UI.WebControls.Button)sender.CommandArgument.ToString();
 
Share this answer
 

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



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