Click here to Skip to main content
15,898,374 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I m using link button in asp.net for handling their event i m using its rowcommand property but it always shows "" (null) value in its e.CommandArgument

this is my code:

ASP.NET
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataSourceID="SqlDataSource1" DataKeyNames = "id" OnRowCommand = "GridView1_RowCommand">
            <columns>
                 <asp:TemplateField>
                    <itemtemplate>
                        <asp:LinkButton ID="LinkButton1" CommandName = "getid" runat="server" 
                            Text='<%# Eval("id") %>' CommandArgument='<%# Eval("id") %>'>
                    </itemtemplate>
                
            </columns>

C#
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        TextBox1.Text = e.CommandName.ToString();
    }

the field eval("id") is not empty. it contains integer values (1,2,3,4,...)

tell me if i m doing something wrong
Posted
Updated 2-Sep-11 8:14am
v2

replace in row command like this

if(e.CommandName=="getid")
TextBox1.Text = e.CommandName.ToString();
 
Share this answer
 
Does your page_load contains
C#
if(!IsPostBack)
 
Share this answer
 
Comments
Sachin gulati 3-Sep-11 2:04am    
no it doesn't have ispostback....
is it required??
Sachin gulati 3-Sep-11 2:18am    
pls tell me how....
User the below link.

http://csharpdotnetfreak.blogspot.com/2009/04/linkbutton-gridview-querystring.html[^]

Hope this will resolve your problem.

Thanks
Rahul
 
Share this answer
 

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