Click here to Skip to main content
15,902,447 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C#
pnlProducts.Visible = true;
           
           int CategoryID = Convert.ToInt16((((LinkButton)sender).CommandArgument));
           GetProducts(CategoryID);


What I have tried:

I got a error input string was not correct format, please give me ideas any one.
Posted
Comments
PIEBALDconsult 15-Feb-16 11:07am    
Use the debugger to see what the actual value of ((LinkButton)sender).CommandArgument is. It probably isn't what you expect.
Boopalslm 15-Feb-16 11:09am    
when i click a LinkButton at that time shown particulate products in my panel.
PIEBALDconsult 15-Feb-16 11:12am    
As I said, "use the debugger".
Maciej Los 15-Feb-16 13:10pm    
What framework: WinControls, WebForms, WPF? Please, type a full name!

1 solution

Whatever is returned by ((LinkButton)sender).CommandArgument can't be converted to Int16. Use the TryParse function instead of Parse so you can handle when the text can't be converted.
 
Share this answer
 
Comments
Boopalslm 15-Feb-16 11:17am    
where i am using TryParse function
F-ES Sitecore 15-Feb-16 11:24am    
Instead of Convert.ToInt16 use Int16.TryParse instead.
Philippe Mori 15-Feb-16 21:10pm    
Read the MSDN documentation!
Boopalslm 16-Feb-16 2:13am    
pnlProducts.Visible = true;

int CategoryID = Int16.TryParse((((LinkButton)sender).CommandArgument));
GetProducts(CategoryID);

Now i am use as per your ideas, but same line is error is came, please give me ideas.
F-ES Sitecore 16-Feb-16 4:30am    
int CategoryID = 0;

if (!Int16.TryParse((((LinkButton)sender).CommandArgument), out CategoryID))
{
// do something to handle when parse fails
}
GetProducts(CategoryID);

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