Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I created a result page in which my result is show on repeater and if result paging number is show on other repeater.
for example:
A
B
C
D
1 2 3 4 5
Here ABCD are the result on one page and 12345 are paging, if i click on 2 then it show me next result like EFGH. Till then it is working fine, but the problem is...
when i have only one result A so that in paging repeater 1 is show
A
1
and when i click on this 1 then it is giving error 'Input string was not in a correct format'
C#
ArrayList pages = new ArrayList();
            for (int i = iStartIndex; i <= iEndIndex; i++)
                if (i == PageNumber)
                {
                    pages.Add("<strong>" + (i + 1).ToString() + "</strong>");
                }
                else
                {
                    pages.Add((i + 1).ToString());
                }

            rptPaging.DataSource = pages;
            rptPaging.DataBind();

protected void rptPaging_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        PageNumber = Convert.ToInt32(e.CommandArgument) - 1; //in this line error is coming.
        BindRepeaterData();
    }
Posted
Updated 5-Jul-14 4:31am
v2
Comments
PIEBALDconsult 4-Jul-14 10:03am    
Use the debugger. Examine the value of e.CommandArgument .
Raj Negi 5-Jul-14 10:36am    
while debugging i found e.CommandArgument contains value 1 but inside the strong tag.
Due to this strong tag error occur.
i found where problem occur, actually i am using strong tag to bold the page number. If i remove strong then no error occur but i want to bold the number. any solution?
DamithSL 4-Jul-14 23:19pm    
update the question with your aspx page repeater code
Raj Negi 5-Jul-14 10:36am    
while debugging i found e.CommandArgument contains value 1 but inside the strong tag.
Due to this strong tag error occur.
i found where problem occur, actually i am using strong tag to bold the page number. If i remove strong then no error occur but i want to bold the number. any solution?

As suggested by PIEBALDconsult in their comment...

Put a breakpoint on the line
PageNumber = Convert.ToInt32(e.CommandArgument) - 1;


Examine the contents of e.CommandArgument

It might be null, it might be text such as "Empty". Whatever it is it will not be the string form of any integer so the Convert.ToInt32 will fail.

Place a check before the code e.g.
C#
if(e.CommandArgument != null) // replace with whatever the offending value is
{
     PageNumber = Convert.ToInt32(e.CommandArgument) - 1;
     BindRepeaterData();
}


[EDIT - update in light of new information]
Match match = Regex.Match(e.CommandArgument, @"\d+", RegexOptions.IgnorePatternWhitespace);
if(match.Success) 
{
     PageNumber = Convert.ToInt32(match.ToString) - 1;
     BindRepeaterData();
}
You will also need the following
using System.Text.RegularExpressions;
 
Share this answer
 
v2
Comments
Raj Negi 4-Jul-14 14:44pm    
while debugging i found e.CommandArgument contains value 1 but inside the strong tag.
Due to this strong tag error occur.
i found where problem occur, actually i am using strong tag to bold the page number. If i remove strong then no error occur but i want to bold the number. any solution?
CHill60 5-Jul-14 10:47am    
I've updated my solution with a way to get the number and still leave the strong tag in place
Raj Negi 5-Jul-14 14:00pm    
error: cannot resolve method match
try below
C#
if(e.CommandArgument != null)
{
    PageNumber =0;
    if(int.TryParse(e.CommandArgument, out PageNumber))
    {
      PageNumber --; 
    }
    BindRepeaterData();
}
 
Share this answer
 
Comments
Raj Negi 5-Jul-14 14:02pm    
error: argument type 'object' is not assignable to parameter type 'string'
your pagenumber variable should be in
Int 
typpe
other wise you need to write this

C#
PageNumber = (Convert.ToInt32(e.CommandArgument) - 1).toString();
 
Share this answer
 
v2
Comments
Raj Negi 4-Jul-14 10:17am    
yes it is in INT

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