Solved

Data binding won't update source.

Posted on 2009-07-15
3
238 Views
Last Modified: 2013-11-26
I have a checkbox in a template field in a gridview.  Two way binding is set for the checkbox control.  But, checking the checkbox does not update the source table.

(Line 26 in the code is the actual bind)

What might I be missing?  Thanks.
<asp:GridView ID="GridViewBrowse" runat="server" AllowSorting="True" 

                        BackColor="White" BorderColor="White" BorderStyle="Ridge"

                        BorderWidth="2px" CellPadding="3" CellSpacing="1" CssClass="TableFont" DataSourceID="SqlDataSourceBrowse"

                        EmptyDataText="Records will be displayed here.  Click select on a record for detailed data"

                        GridLines="None" Height="1px" PageSize="6" TabIndex="3" Width="762px" 

                        AutoGenerateColumns="False">

                        <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />

                        <Columns>

                            <asp:BoundField DataField="TicketID" HeaderText="TicketID" SortExpression="TicketID" />

                            <asp:BoundField DataField="Reception Number" HeaderText="Reception Number" SortExpression="Reception Number" />

                            <asp:BoundField DataField="Submitted By" HeaderText="Submitted By" SortExpression="Submitted By" />

                            <asp:BoundField DataField="Submit Date" HeaderText="Submit Date" 

                                SortExpression="Submit Date" />

                            <asp:BoundField DataField="Update Type" HeaderText="Update Type" SortExpression="Update Type" />

                            <asp:BoundField DataField="Brief Desc" HeaderText="Brief Desc" 

                                SortExpression="Brief Desc">

                            </asp:BoundField>

                            <asp:BoundField DataField="Submiters Comments" HeaderText="Submiters Comments" 

                                SortExpression="Submiters Comments" />

                            <asp:BoundField DataField="Complete" HeaderText="Complete" 

                                SortExpression="Complete" />

                            <asp:BoundField DataField="Schedule Count" HeaderText="Schedule Count" 

                                SortExpression="Schedule Count" />

                            <asp:TemplateField HeaderText="test templet">

                                <ItemTemplate>

                                    <asp:CheckBox ID="CheckBox2" runat="server" Checked='<%# Bind("Archived") %>' 

                                        AutoPostBack="True" oncheckedchanged="CheckBox2_CheckedChanged" />

                                </ItemTemplate>

                            </asp:TemplateField>

                        </Columns>

                        <RowStyle BackColor="#DEDFDE" ForeColor="Black" />

                        <EditRowStyle Wrap="False" />

                        <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />

                        <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />

                        <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />

                    </asp:GridView>

Open in new window

0
Comment
Question by:sabev
  • 3
3 Comments
 

Author Comment

by:sabev
ID: 24863062
Or, if when CheckBox_CheckedChanged event is fired, if I could determine the row of the GridView the checkbox is in, that would be even better.  It should have some parent and location information, shouldn't it?

thanks
0
 

Author Comment

by:sabev
ID: 24869082
(Notes for the OP):

The original databinding problem is not so much an issue as getting the RowIndex when the checkbox is changed.

hmm....  I have tried adding onRowCommand="MyDataGrid_EditCommand" to the <asp:GridView object, hoping it would call the code behind "MyDataGrid_EditCommand" sub routine when the checkbox is checked but it does not call it.

It does not seem like I can pass the RowIndex on the CheckBox_CheckedChanged event.

Is there some event within the GridView that I can get to fire when a checkbox located in a template is checked?

I've tried -
OnRowCommand
OnRowEditing
OnRowUpdating

With no luck.

Thanks
0
 

Accepted Solution

by:
sabev earned 0 total points
ID: 24870376
I figured it out...  at least how the get the row index on check box changed.  That will solve my problem
It's simple.

    Protected Sub CheckBox2_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim gvRow As GridViewRow
        Dim chkbx As CheckBox
        Dim intRowIndex As Integer

        chkbx = sender
        gvRow = chkbx.Parent.Parent
        intRowIndex = gvRow.RowIndex
' perform work agains that row here
end sub


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now