tags:

views:

68

answers:

3

property in my mainClass

  public Int64 DetailID
        {
            get { return bintDetailID; }
            set { bintDetailID = value; }
        }

myClass

mainClass obj=new mainClass();
obj.DetailID = int.Parse(e.CommandArgument.ToString());

aspx page

<asp:Button ID="btnEdit" Text="Edit" CommandArgument='<%#Eval("DetailID") %>'
CausesValidation="false" CommandName="Edit" Visible="false" runat="server" OnCommand="btnEdit_Click"/>

Isn't this how u convert string to int ?

int.Parse(e.CommandArgument.ToString());

Whats wrong ? plz help..thnx

+1  A: 

Assuming that your Button object is NOT within a databound control like a grid / repeater, AND If you are trying to Bind the button using the DetailID property, check the following:-

  1. Assuming your button is in testPage.aspx, the codebehind class for testPage.aspx i.e class testPage should have a property of type Int64 called DetailID. eg : Int64 DetailID get; set;

  2. Assuming mainClass is some custom class of yours, somewhere in Page_Load, you will have to do a this.DetailID = mainClassObject.DetailID; where this = instance of your page.

  3. In your page_load method, additionally, you will have to do a Page.DataBind(). This is because a non-databound control like button does not have its own DataBind() method.

Note 1: If your testPage.DetailID = Int32 / int, you will need to do the conversion in the setter method or before that as y0ur mainClass is an Int64

Note 2: From your comments, you seem to be saying that Int64 doesnt exist. Which is weird! Try using the fully qualified name i.e System.Int64 and see if that works!

InSane
I tried that already..it said Int64 doesn't exist in the current context (!!??)
Serenity
@Happy Soul - if your button is NOT WITHIN a databound control, like a Grid, then you can check my updated answer and see if it works!!
InSane
k..thnx..will try that
Serenity
ok I have implemented like u said..now the master Page of my aspx page is throwing "Object reference null exception" when I include the line "Page.DataBind();" in my code.. when I comment out this line in my PageLoad method this exception is not thrown BUT again the e.commandArguments becomes empty string like "" how do I use thsi non data bound control ? plz help..thnx
Serenity
@Happy Soul - What `Page.DataBind()` does is that it binds all datasources on your page to their respective controls. What is the code of the line where you are getting your object reference error from? Can u ascertain if all other datasources on your page are populated with values BEFORE u do the Page.DataBind(). If any of your datasources are not populated, you are likely to get an object reference error. To test if this part works ok, i suggest you first comment out all other datasources / databound controls on your page...
InSane
+4  A: 

Hello ,

Int.parse is used to covert into 32 bit integer value.According to your question

 public Int64 DetailID
        {
            get { return bintDetailID; }
            set { bintDetailID = value; }
        }

Its 64 bit.

try Int64.parse(e.CommandArgument.ToString());

if you are getting empty value check

 (!string.IsNullOrEmpty(e.CommandArgument.ToString())
Int64.parse(e.CommandArgument.ToString());

Hope it works.

Thanks

PrateekSaluja
I have tried that already..it says int64 doesnt exist in the current context..why is that ??
Serenity
argh..why did C# had to be case sensitive!? sry :/ was typing "int64" instead of "Int64" ..ok now the exception still is being thrown..still the string is empty only :( why wont it fetch the value :((
Serenity
Hey check the value of e.CommandArgument.ToString().
PrateekSaluja
@Prateek..its empty string..the button's not inside of a data bound control..trying that now..new to all this so thot Eval method might work with controls not inside of data bound controls too..thnx for trying to help
Serenity
May be a case:-check value of <%#Eval("DetailID") %>
PrateekSaluja
@Happy Soul:-Your welcome hope you will solve the issue very soon.Good luck.
PrateekSaluja
A: 

Just to be sure, try setting the value for CommandArgument from the code-behind ...

btnEdit.CommandArgument = DetailID.ToString();

One doubt I have though, is if in your .aspx file you should write

CommandArgument='<%=Eval("DetailID") %>'

instead of

CommandArgument='<%#Eval("DetailID") %>'

(note the = vs #)

tsimbalar