Click here to Skip to main content
15,918,193 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a gridview.In this I have a linkbuton called "edit".When we click the Edit its getting the particular row ID through Command Argument.But i want the command argument value outside the Gridview eventargs .

What I have tried:

I tried Viewstate and session but i cant to get the values.
Posted
Updated 19-Dec-16 0:14am

1 solution

ASP.NET
<asp:GridView ID="MyGridView" runat="server">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:LinkButton ID="MyLinkButton" CommandArgument="A" CommandName="Link" runat="server">Click</asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>


C#
MyGridView.DataSource = data;
MyGridView.DataBind();

foreach (GridViewRow row in MyGridView.Rows)
{
    // The linkbutton is in the first cell in my example
    TableCell cell = row.Cells[0];

    LinkButton MyLinkButton = (LinkButton)cell.FindControl("MyLinkButton");

    System.Diagnostics.Debug.WriteLine(MyLinkButton.CommandName);
    System.Diagnostics.Debug.WriteLine(MyLinkButton.CommandArgument);
}
 
Share this answer
 
Comments
Member 12857356 19-Dec-16 6:27am    
Y we Cant Pass values through session or viewstate
F-ES Sitecore 19-Dec-16 6:43am    
You can if you want but you'd have to put the relevant data in the session or viewstate yourself. You'll need to explain what it is you're trying to do.
Member 12857356 19-Dec-16 6:52am    
Fr example:
I am using the Linkbutton Called Edit.When we click a edit button the edit page will shown.After we change the Datas I have to update the Changed datas ty database.In this case i want my ID to update my datas.

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