Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have gridview. and i want to show 3 links accept, confirm,decline in one headertext:action.when i click on accept link that time it should change in accepted.
Posted
Updated 30-Dec-12 18:31pm
v2

1 solution

use the following code
test.aspx:

XML
<asp:TemplateField HeaderText="Action">
                <ItemTemplate>
                    <asp:LinkButton ID="lnkaccept" runat="server" Text="Accept" CommandName="Accept"></asp:LinkButton>&nbsp; | &nbsp;
                    <asp:LinkButton ID="lnkconfirm" runat="server" Text="Confirm" CommandName="Confirm"></asp:LinkButton>&nbsp; | &nbsp;
                    <asp:LinkButton ID="lnkdecline" runat="server" Text="Decline" CommandName="Decline"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>


test.aspx.cs file

protected void test_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Accept")
            {
                GridViewRow row = (GridViewRow)((LinkButton)(e.CommandSource)).NamingContainer;
                LinkButton lnkAccept = (LinkButton)row.FindControl("lnkaccept");
                try
                {
                    //do your task here
                    lnkAccept.Text = "Accepted";
                }
                catch (Exception ex)
                {
                    lnkAccept.Text = "Accept";
                }
            }
        }
 
Share this answer
 
Comments
Member 9027346 31-Dec-12 2:27am    
it works..but if i again run this program it again showing accept.i want to show accepted still not changing the record from database..
Vishal.Shimpi144 31-Dec-12 3:02am    
use row databound event in the check the rowtype if it is datarow the check your condition if your condition is true the make link button text as Accepted like:
protected void test_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

if (check The condition here)
{
LinkButton lnk = (LinkButton)e.Row.FindControl("lnkaccept");
lnk.Text = "Accepted";
}
}
}

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