0

I have a gridview with Template field. I add a checkbox in templatefield . Autopostback is true for checkbox .

I fill grid in Load-page and creted column dynamic .

 if (!IsPostBack)
        {
         FillGrid();
        }

I use update panel

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
 <ContentTemplate>
<SharePoint:SPGridView ID="grid" AllowSorting="true" AllowFiltering="true"    CssClass="ms-listviewtable"  
runat="server" AutoGenerateColumns="false">
<RowStyle CssClass="ms-alternating" Height="10px" />
<Columns>
    <asp:TemplateField> 
        <ItemTemplate  >
            <asp:CheckBox ID="select" runat="server" 
                OnCheckedChanged="select_CheckedChanged" AutoPostBack="true"  />
            <input id="Display" type="hidden" runat="server" />
            <input id="itemID" type="hidden" runat="server" />
            <asp:Image ID="icon" runat="server" Height="10px" Visible="false"  />
        </ItemTemplate>
        <ItemStyle Width="35px" />
    </asp:TemplateField>
    <asp:TemplateField >
     </asp:TemplateField>
</Columns>
</SharePoint:SPGridView>
 </ContentTemplate>
  <Triggers>
<asp:AsyncPostBackTrigger ControlID="select" EventName="OnCheckedChanged" />
 </Triggers>
 </asp:UpdatePanel>

but show error :A control with ID 'select' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.

My problem is : When checkbox is change, page refresh

I don't want to refresh page after checkedchange!

4
  • If autopostback is true for checkbox then the page will refresh , you could try to use update panel for partial page refresh Commented Apr 7, 2012 at 5:56
  • I use Update panel . plz see question, i edit Commented Apr 7, 2012 at 6:03
  • What does your FillGrid method look like? SO has a simular question stackoverflow.com/questions/5476766/… Commented Apr 7, 2012 at 6:05
  • I bind grid in FillGrid(). I have a special column that is Linkbutton and they fill in RowDataBound . when page refresh , they do'y bind. Commented Apr 7, 2012 at 6:13

3 Answers 3

1

you have to set autopostback="false" or remove autopostback property in checkbox. autopostback actully refresh the page.

Sign up to request clarification or add additional context in comments.

7 Comments

can you please specify what u want to do in checkbox change event ? is it possible to accomplish your task using client side event ??
I want add a Attributes for a control. and visible a control if row selected is one.
you can do your task using handling client side event. simply write a javascript function pass the control's id and set attributes and visibility in js function.
No, i should reed all row and change Attributes for a control .
why you need to read all row ?? cant you pass Image Client Id in each checkbox onclick function ? function will take care of single object only..
|
1

So what happens if you set the autopostback property of the checkbox to false?

Also if you are actually looking to handle the onchange event of the checkbox you could wrap the grid with an UpdatePanel; the user wouldn't see a postback but you still get the flexibility of serverside event handling.

1 Comment

grid have not autopostback property.
0

First of all you need changes templetecolumn as below

<asp:TemplateField>
            <ItemTemplate>
                <asp:CheckBox ID="chkselect" runat="server" />
                <input id="Display" type="hidden" runat="server" />
                <input id="itemID" type="hidden" runat="server" />
                <asp:Image ID="imgicon" runat="server" Height="10px" Style="display: none;" ImageUrl="~/images/arrow_left.jpg" />
            </ItemTemplate>
            <ItemStyle Width="35px" />
        </asp:TemplateField>

Now handle itemdatabound event in server side code

Protected Sub SPGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvBanner.RowDataBound
    If e.Row.RowType = DataControlRowType.DataRow Then
        Dim chkselect As CheckBox = e.Row.FindControl("chkselect")
        Dim imgicon As Image = e.Row.FindControl("imgicon")
        If chkselect IsNot Nothing Then
            chkselect.Attributes.Add("onclick", "javascript:DoMyTask(this,'" + imgicon.ClientID + "')")
        End If
    End If
End Sub

Now specify JavaScript function in aspx page as below.

<script type="text/javascript" language="javascript">
    function DoMyTask(obj, imgid) {            
        var objCheck = obj.checked;
        var objimg = document.getElementById(imgid)
        if (objCheck == true) {
            objimg.style.display = "block";
            //set more attributes over here
        }
        else {
            objimg.style.display = "none";
            //set more attributes over here
        }
        var count = $(":checkbox:checked").length;
        alert('you have selected ' + count + ' Rows');
    }

</script>

Hope this will help you...happy coding ..

7 Comments

Thanks a lot :).But how do i count selected row?
selected row means the row having checkbox checked right ?? and you need to count those rows having tick mark chekbox right ??
yes, I want count selected row , and add Attributes for a linkbutton control on page and enable this.
you can get count by using $(":checkbox:checked").length; this. i will modify js function .add count in alert
i have tested it..you can use this code. when you checked checkbox it will alert msg for how many rows you have selected. :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.