Last post Jul 18, 2010 02:17 AM by tharuraju
Jul 16, 2010 03:26 PM|tharuraju|LINK
I have developed a user control consisting of Datalist that has a LinkButton in the
<item Template> ie
<asp:DataList id="userContents" runat="server" OnItemCommand="userContents_ItemCommand" OnItemCreated="userContents_ItemCreated" OnSelectedIndexChanged="userContents_SelectedIndexChanged" >
<asp:LinkButton id = "HyperLink1" runat="server" Font-Names="Verdana" Font-Size="XX-Small"
ForeColor="#0000cd" Text='<%# DataBinder.Eval(Container.DataItem, "Text") %>'
CommandArgument ='<%# DataBinder.Eval(Container.DataItem,"CmdObject")%>'
Now i want to pass an "CmdObject" through DataListCommandEventArgs
protected void userContents_ItemCommand(object source, DataListCommandEventArgs e)
//have the event handler code here
//i want to have the "CmdObject" somehow
//ie to say e.Items.Controls .. i should be able to cast it to the particular class
UserDetail user = (UserDetail)e.Item.Control;
//basically i want the object of UserDetail class through the e
Very urgent and important .. pls
Jul 16, 2010 05:46 PM|sansan|LINK
You have to give CommandName property of the link button so that you can check for type of command in case if you have multiple buttons performing multiple actions
protected void userContents_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
object objCommand = e.CommandArgument;
You can get your object in this manner
then you can cast it to integer, string etc.,
Is that what you are trying to do
Jul 17, 2010 01:58 AM|tharuraju|LINK
Dear santhosh ,Thanks for ur reply dear
but my problem is still not solved ie
object obj = e.CommandArgument;
userDetail user = (userDetail)obj;
I'm getting a cast error dear . ie not able to cast string to so and so userDetail .
Actually userDetail class has a property like
public userDetail CmdObject
u = value;
i hope now u have a clear picture ,any ways thanks for the quick reply but pls do help me !!
Jul 17, 2010 02:10 AM|py1984|LINK
I think u will not class directly to command argument ... better u keep your collection in viewstate or session and keep item index in command arguments and through index u retrieve particular object from server side.
Jul 17, 2010 02:16 AM|sansan|LINK
I don't think you can keep an custom class there
it should be either string or an integer.
try saving an integer or string and rebuild the class based on the Command Argument
say, for example Building User Information based on User ID coming from Command Argument
but I think there is no mechanism to save the objects as such.
Try my suggestion and let me know
Jul 18, 2010 02:17 AM|tharuraju|LINK
I tried keeping the objects in a List ie (List<userDetail> ) inside my userControl and the problem got solved i'm able to
index using an Integer , so thanks ,wht i should have kept in my mind while designing was that the return type of the
CommandArgument is string type and it can only represent the name of the object , but not the object with data in it !!!