Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6166277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:18:37+00:00 2026-05-23T22:18:37+00:00

<asp:GridView ID=gvBlockUnblock runat=server AutoGenerateColumns=False BackColor =AliceBlue onrowdatabound=gvBlockUnblock_RowDataBound DataKeyNames=CPID,PUBLISHED style=margin-top: 0px AllowPaging=True onpageindexchanging=gvBlockUnblock_PageIndexChanging PageSize=10 EnableViewState=

  • 0
<asp:GridView ID="gvBlockUnblock" runat="server" AutoGenerateColumns="False" 
                       BackColor ="AliceBlue"
                      onrowdatabound="gvBlockUnblock_RowDataBound" DataKeyNames="CPID,PUBLISHED"
                    style="margin-top: 0px" 
                    AllowPaging="True" onpageindexchanging="gvBlockUnblock_PageIndexChanging" 
                    PageSize="10" EnableViewState= "true"
                    onselectedindexchanged="gvBlockUnblock_SelectedIndexChanged" >

        <Columns>

                    <asp:TemplateField HeaderText="S.No.">
                    <ItemTemplate>
                    <asp:LinkButton ID="lbSNo" runat="server" 
                    Text='<%# (Eval("sno")) %>'
                    PostBackUrl='<%#"~/_UILayer/ComplaintReport.aspx?PINo="+Eval("CPID") %>' >
                    </asp:LinkButton>
                    </ItemTemplate>
                    </asp:TemplateField>

         <asp:BoundField  HeaderText = "Complaint" />

         <asp:HyperLinkField   DataNavigateUrlFields="CPID" datatextfield = "CPID"
                DataNavigateUrlFormatString="WebForm1.aspx?CPID={0}" HeaderText=" Problem Item No"/>


            <asp:BoundField  DataField="NewComplaints" 
                HeaderText="Number of New Complaints" SortExpression="NewComplaints" />
            <asp:BoundField DataField="TotalNumberofComplaints" 
                HeaderText="Total Number of Complaints" SortExpression="TotalNumberofComplaints" />
            <asp:BoundField DataField="NumberofUnblocks" HeaderText="Number of Unblocks" 
                SortExpression="TotalNumberofComplaints" />



          <asp:TemplateField  HeaderText = "Comments">
           <ItemTemplate>
                        <asp:TextBox ID="txtAdminComment" Font-Names="Arial" ReadOnly="false" Width="200" Height="30"
                            TextMode="multiLine" runat="server" BorderStyle="NotSet"></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>


           <asp:TemplateField  HeaderText = " Block / Unblock">
                <ItemTemplate>
                     <asp:button ID ="btnBlockUnblock"  runat = "server" 
                         Text = '<%# CheckBlock(Eval("PUBLISHED")) %>' CommandName="Select" 
                        CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"  CausesValidation="False"  />
                </ItemTemplate>
            </asp:TemplateField>



                    <asp:HyperLinkField   DataNavigateUrlFields="CPID"  Text="View Details"  
                DataNavigateUrlFormatString="ItemHistoryForm.aspx?CPID={0}" HeaderText=" Problem Item No"/>

        </Columns>
    </asp:GridView>

aspx.cs

   protected void gvBlockUnblock_SelectedIndexChanged(object sender, EventArgs e)
    {
        string ComplaintProfileId = gvBlockUnblock.DataKeys[gvBlockUnblock.SelectedIndex].Values["CPID"].ToString();
        string ISPUBLISHED = gvBlockUnblock.DataKeys[gvBlockUnblock.SelectedIndex].Values["PUBLISHED"].ToString();

        string date = System.DateTime.Now.ToString();
        TextBox tb = (TextBox)gvBlockUnblock.Rows[gvBlockUnblock.SelectedIndex].FindControl("txtAdminComment");
        string Comment = tb.Text;
        if (string.IsNullOrEmpty(Comment))
        {

            WebMsgBox.Show("empty");
        }
        else
        {
            if (ISPUBLISHED == "N")
            {
                ISPUBLISHED = "N";
            }
            else
            {
                ISPUBLISHED = "Y";
            }
            string AdminComment = (System.DateTime.Now.ToString() + " :  " + Comment);

            AddCommentBLL.InsertComment(AdminComment, ComplaintProfileId, ISPUBLISHED);
            gvBlockUnblock.DataSource = AddCommentBLL.GetItem();
            gvBlockUnblock.DataBind();
        }
    }

So, on click of the button ID =”btnBlockUnblock”, this grid view selectedindex changed needs to fire. The page is refreshing though.

Thanks
Sun

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:18:39+00:00Added an answer on May 23, 2026 at 10:18 pm

    You have to use the GridView RowCommand event instead of the GridView SelectedIndex Change.. e.g

    protected void gvBlockUnblock_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Select")
        {
    
    string ComplaintProfileId = gvBlockUnblock.DataKeys[gvBlockUnblock.SelectedIndex].Values["CPID"].ToString();
        string ISPUBLISHED = gvBlockUnblock.DataKeys[gvBlockUnblock.SelectedIndex].Values["PUBLISHED"].ToString();
    
        string date = System.DateTime.Now.ToString();
        TextBox tb = (TextBox)gvBlockUnblock.Rows[gvBlockUnblock.SelectedIndex].FindControl("txtAdminComment");
        string Comment = tb.Text;
        if (string.IsNullOrEmpty(Comment))
        {
    
            WebMsgBox.Show("empty");
        }
        else
        {
            if (ISPUBLISHED == "N")
            {
                ISPUBLISHED = "N";
            }
            else
            {
                ISPUBLISHED = "Y";
            }
            string AdminComment = (System.DateTime.Now.ToString() + " :  " + Comment);
    
            AddCommentBLL.InsertComment(AdminComment, ComplaintProfileId, ISPUBLISHED);
            gvBlockUnblock.DataSource = AddCommentBLL.GetItem();
            gvBlockUnblock.DataBind();
        }
        }
    }
    

    Edit: After reading code from your comment, I found your problem.

    What happens actually, when you click the button, the Page Load event fires before your gridview event and there your gridview data again binded and it lost your fired event. You have to examine your page Postback by putting if(!IsPostBack) in your page load where you are trying to bind your data to gridview.

        protected void Page_Load(object sender, EventArgs e)
        {
         if(!IsPostBack)
         {
            // gets the items table using stored proc GetItem
            gvBlockUnblock.DataSource = AddCommentBLL.GetItem();
            gvBlockUnblock.DataBind();
            // used for paging
            Session["MyDataSett"] = gvBlockUnblock.DataSource;
         }
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sample <asp:GridView ID=data_basic_addresses runat=server AllowPaging=False BorderWidth=0 AllowSorting=True AutoGenerateColumns=False DataKeyNames=AddressId HorizontalAlign=Center DataSourceID=LinqAddressDS PageSize=20 CssClass=GridViewClass> <Columns>
<asp:GridView ID=GridView1 runat=server AutoGenerateColumns=False BackColor=White BorderColor=#CC9966 BorderStyle=None BorderWidth=1px CellPadding=4> <Columns> <asp:BoundField DataField=FileID HeaderText=FileID />
I have this code <asp:GridView ID=gvCentersList runat=server AutoGenerateColumns=False DataKeyNames=CenterID DataSourceID=SqlDataSource1 CssClass=gv-classic> <Columns> <asp:TemplateField HeaderText=>
i have the following gridview <asp:GridView ID=GridView3 runat=server AllowPaging=True AllowSorting=True AutoGenerateColumns=False DataKeyNames=ID DataSourceID=CommentsDataSource> <Columns>
I have the following gridview <asp:GridView DataSourceID=odsRooms DataKeyNames=id,objectid ID=gvRooms PageSize=10 runat=server AutoGenerateColumns=False > <Columns>
<asp:GridView ID=GridView1 runat=server AutoGenerateColumns=False AllowPaging=true AllowSorting=true PageSize=10 DataKeyNames=CategoryID onselectedindexchanged=GridView1_SelectedIndexChanged GridLines=Vertical onrowediting=GridView1_RowEditing onrowcancelingedit=GridView1_RowCancelingEdit onrowupdating=GridView1_RowUpdating onsorted=GridView1_Sorted
i have a asp.net webpage with a GridView <asp:GridView ID=grid_view runat=server AllowPaging=True AutoGenerateColumns=False BackColor=White
Below is my gridview <asp:GridView ID=GridView1 runat=server AutoGenerateColumns=False EnableModelValidation=True onrowdatabound=GridView1_RowDataBound onrowcommand=GridView1_RowCommand onrowdeleting=GridView1_RowDeleting> <asp:TemplateField HeaderText=Amount
Not giving multiline text in gridview cell <asp:GridView ID=GridView1 runat=server AutoGenerateColumns=False DataKeyNames=CategoryID DataSourceID=SqlDataSource1 ShowFooter=true
I have the following GridView <asp:GridView ID=GridView1 runat=server AllowPaging=True OnRowCommand=GridView1_RowCommand DataKeyNames=Chart_Id AutoGenerateColumns=False EnableModelValidation=True >

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.