Not Getting the value of link button command argument

Posted by Vijayar under C# on 2/23/2012 | Points: 10 | Views : 25162 | Status : [Member] | Replies : 8
Hi .I tried in both the ways .But I am not getting value of command argument.Where is my mistake.Help Me .It's Very Urgent.The link button is placed inside a panel
<asp:LinkButton ID="lnkapply" runat="server" CommandName="Id" OnClick="lnkapply_Click" CommandArgument='<%# Bind("JobId") %>' CssClass="style" >Apply</asp:LinkButton>

protected void lnkapply_Click(object sender, EventArgs e)
{


try
{
string id = ((LinkButton)sender).CommandName;
string id1= (lnkapply.CommandArgument.ToString());
//string id = lnkapply.CommandArgument;
Response.Redirect("frmApplyJob.aspx");

}
catch (Exception ex)
{
logger.Error("General Exception", ex);
}
}


<asp:LinkButton ID="lnkapply" runat="server" CommandName="Id" OnClick="lnkapply_Click" CommandArgument='<%# Eval("JobId") %>' CssClass="style" >Apply</asp:LinkButton>

vijaya


Responses

Posted by: Blessyjees on: 2/23/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi,

Can you try with e. CommandArugment.ToString() instead of (lnkapply.CommandArgument.ToString());

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 2/23/2012 [Member] Bronze | Points: 25

Up
0
Down
Try this

<asp:LinkButton ID="lnkapply" runat="server" CommandName="Id" OnClick="lnkapply_Click" CommandArgument='<%# Bind("JobId") %>' CssClass="style" >Apply</asp:LinkButton>


protected void lnkapply_Click(object sender, EventArgs e)
{


try
{
string id = ((LinkButton)sender).CommandName;
string id1= ((LinkButton)sender).CommandArgument.ToString();
//string id = lnkapply.CommandArgument;
Response.Redirect("frmApplyJob.aspx");

}
catch (Exception ex)
{
logger.Error("General Exception", ex);
}
}


<asp:LinkButton ID="lnkapply" runat="server" CommandName="Id" OnClick="lnkapply_Click" CommandArgument='<%# Eval("JobId") %>' CssClass="style" >Apply</asp:LinkButton>


Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ppathi on: 2/23/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

I have tried with repeater i can able to pass jobid. Sample code is

Bind your career details in to repeater like this

<asp:Repeater ID="career_rep" runat="server" OnItemCommand="career_Ontem" >
<ItemTemplate>
<tr style="height:35px">
<td class="CarrBoxtxt BG_CarrGrey" style="width:177.75px;padding-left:15px" align="right">
<asp:LinkButton ID="cdetail" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Designation").ToString()%>' CommandArgument='<%#DataBinder.Eval(Container.DataItem,"jobid").ToString()%>' CommandName="Id"></asp:LinkButton>
</td>
</tr>
</td>
</ItemTemplate>
</asp:Repeater>

and code behind side u should write OnItemCommand Event like this

protected void career_Ontem(object sender, RepeaterCommandEventArgs e)
{

string code=(string)e.CommandArgument;
Response.Write("/Career-Details.aspx?jobid="+ code);


}



Thanks & Regards,
Pasupathi G
No Pain No Gain

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijayar on: 2/23/2012 [Member] Starter | Points: 25

Up
0
Down
Hi
I am placing link button in a panel.How to pass the id of particular item as command argument.

vijaya

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ppathi on: 2/23/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

Try this. I have give dummy inputs

<asp:Panel ID="panel1" runat="server">
<asp:LinkButton ID="fir" runat="server" CommandArgument='5' CommandName='1' oncommand="fir_Command" Text="d"></asp:LinkButton>
</asp:Panel>

codebehind

protected void fir_Command(object sender, CommandEventArgs e)
{
string id = (string)e.CommandArgument;
Response.Write("/Career-Details.aspx?jobid=" + id);
}

Hope this solve your problem

Thanks & Regards,
Pasupathi G
No Pain No Gain

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijayar on: 2/23/2012 [Member] Starter | Points: 25

Up
0
Down
HI
I need the id from database only


vijaya

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ppathi on: 2/23/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

OK Please attach your complete code for giving better solution


Thanks & Regards,
Pasupathi G
No Pain No Gain

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ppathi on: 2/23/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

I think panel is not a data control, so you cannot databind a datasource to a panel.

or Put a DataBinding Control inside a Panel. you can get jobid from db

Refer this link

http://forums.asp.net/t/1750394.aspx/1

Thanks & Regards,
Pasupathi G
No Pain No Gain

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response