Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7506729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:20:26+00:00 2026-05-29T22:20:26+00:00

Is it possible to cast a command-line passed string object back to actual object?

  • 0

Is it possible to cast a command-line passed string object back to actual object?

I want to do the following, but throwing error can’t cast.

 Button objPro = (Button) sender;
 cProduct cp = (cProduct) objPro.CommandArgument;

If no, then why?

This is what the string holds.

 cProduct cpObj = (cProduct)e.Row.DataItem;
 Button btnAddProduct = (Button)e.Row.FindControl("btnAddProduct");
 if (btnAddProduct != null)
 {
     btnAddProduct.CommandArgument = cpObj.ToString();
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:20:27+00:00Added an answer on May 29, 2026 at 10:20 pm

    You probably can’t, because it’s a string. It’s not a cProduct (whatever that is – consider following .NET naming conventions and naming it Product instead).

    Now you could do this if you had a explicit conversion operator in cProduct to create an instance from a string.

    You haven’t really explained what’s in the string, or what’s in the type – but if your cProduct type provides a ToString method which contains all the data in a reversible form, then you could easily write a method or a constructor to create the product again:

    Product product = new Product(objPro.CommandArgument);
    

    or maybe:

    Product product = Product.Parse(objPro.CommandArgument);
    

    You’ll have to write that constructor/method, of course.

    I would strongly recommend using a constructor or method instead of an operator, just to keep your code clearer – it’s very rarely a good idea to write your own conversion operators.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Java, is it possible to attempt a cast and get back null if
Possible Duplicate: Cast string to enum with enum attribute I have a enum like
I'm wondering if it's possible to cast an object to a Type... I've just
Is it possible to cast an object to the type returned from GetType() ?
Possible Duplicate: CAST and IsNumeric I have a database column that is nvarchar, but
Possible Duplicate: EF4 Cast DynamicProxies to underlying object I'm trying to figure out how
Is it possible to cast an object from a base to a derived one?
is it possible to cast as an interval in MySQL? I want to evaluate
Is it possible to cast a custom class to a value type? Here's an
Possible Duplicate: Puzzling Enumerable.Cast InvalidCastException Hi, I just noticed something quite strange with the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.