Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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 30-Dec-12 19:30pm
Edited 30-Dec-12 19:31pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

use the following code
test.aspx:
 
<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";
                }
            }
        }
  Permalink  
Comments
Member 9027346 at 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 at 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)

  Print Answers RSS
0 OriginalGriff 6,569
1 Sergey Alexandrovich Kryukov 6,168
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 31 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100