This is a migrated thread and some comments may be shown as answers.

Asp.Net Gridview Checkbox changed and Loading Panel Issue.

1 Answer 157 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prasanth100
Top achievements
Rank 1
Prasanth100 asked on 23 Oct 2012, 08:58 AM
Hi,
   I have an Asp.net Gridview (not Telerik gridview),with checkbox in it. I have button(checkAll) on the top.
when i click the top button,it will check all the checkbox in the Gridview, and when i click on CheckBox inside Gridview
it should display Selected Item.

I have used AjaxLoading Panel, Now it is working only for Button click,
But it is not working for checkbox clicked.

Here is the Below Code :
  
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="DUMMY_Default" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">


     <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
     
         <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>


            <telerik:AjaxSetting AjaxControlID="btn1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="GridView1" />
               
                </UpdatedControls>
            </telerik:AjaxSetting>




            
            <telerik:AjaxSetting AjaxControlID="CheckBox1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="GridView1" />
               
                </UpdatedControls>
            </telerik:AjaxSetting>
            
         </AjaxSettings>
    </telerik:RadAjaxManager>

 <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
    </telerik:RadAjaxLoadingPanel>

 <div>
    <asp:Button ID="btn1" runat="server" Text="CheckAll" OnClick="btn1_Click" />
<asp:Panel ID="PanelGrid" runat="server">
    <asp:GridView ID="GridView1" runat="server" DataKeyNames="AnnouncementID"
     AutoGenerateColumns="false" OnRowDataBound="GridView1_OnRowDataBound"
      OnRowCommand="GridView1_OnRowCommand">
      <Columns>
      <asp:TemplateField>
      <ItemTemplate>
      <asp:CheckBox ID="CheckBox1" runat="server"  AutoPostBack="true" OnCheckedChanged="CheckBox1_OnCheckedChanged"/>
      </ItemTemplate>
      </asp:TemplateField>


      <asp:TemplateField>
      <ItemTemplate>
      <asp:Label ID="lblAnnouncementID" runat="server" Text='<%#Eval("AnnouncementID")%>'></asp:Label>
      <asp:LinkButton ID="lnkAnnouncementID" runat="server" Text="Edit" CommandName="Editing" CommandArgument='<%#Eval("AnnouncementID") %>'></asp:LinkButton>
      </ItemTemplate>
      </asp:TemplateField>


      <asp:TemplateField>
      <ItemTemplate>
      <asp:Label ID="lblTitle" runat="server"></asp:Label>
      </ItemTemplate>
      </asp:TemplateField>


      <asp:TemplateField>
      <ItemTemplate>
      <asp:Label id="lblMessage" runat="server"></asp:Label>
      </ItemTemplate>
      </asp:TemplateField>

 </Columns>
      </asp:GridView>
      </asp:Panel>


      <br />
     <asp:TreeView  
                ID="TreeView1"
                ExpandDepth="0" 
                PopulateNodesFromClient="true" 
                ShowLines="true" 
                ShowExpandCollapse="true" 
                runat="server"
               
                 OnSelectedNodeChanged="TreeView1_OnSelectedNodeChanged" />


                 <br />
                 <asp:Label ID="lblmsg" runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>



Code Behind
--------------------
 protected void CheckBox1_OnCheckedChanged(object sender, EventArgs e)
    {
        CheckBox chk = (CheckBox)sender;
        if (chk.Checked)
        {
            lblmsg.Text = "CheckBox chaecked";
        }
    }


    protected void btn1_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in GridView1.Rows)
        {
           // GridViewRow gvRow = (GridViewRow)GridView1.FindControl("GridView1");
            CheckBox CheckBox1 = (CheckBox)row.FindControl("CheckBox1");
            CheckBox1.Checked = true;
        }
    }


Please help me with this,Its very urgent,Awaiting for your response.

Regards,
  Prasad 

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 26 Oct 2012, 07:28 AM
Hello Prasanth,

You will need to define the Label too as an Updated control on checkbox click:
<telerik:AjaxSetting AjaxControlID="CheckBox1">
    <UpdatedControls>
        <telerik:AjaxUpdatedControl ControlID="GridView1" />
        <telerik:AjaxUpdatedControl ControlID="lblmsg" />
    </UpdatedControls>
</telerik:AjaxSetting>

I hope this will prove helpful. Please give it  a try and let me know about the result.

All the best,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Prasanth100
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or