Keeping Grid Checkbox Control matched with correct row

M

Micah N

Greetings,

I have an issue that I am not seeing a blatant solution for. My DataGrid is
an "Accept/Reject" type grid. So there is a check box in a template
control..like this.

<asp:TemplateColumn HeaderText="Employee Name"
SortExpression="EmployeeName">
<ItemTemplate>
<asp:LinkButton ID="LBEmployeeName" Runat="server"
CommandName="EmpName" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Timecard_Total" HeaderText="Hours" />
<asp:TemplateColumn HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkSelect" Runat="server" ></asp:CheckBox>
<------
</ItemTemplate>
</asp:TemplateColumn>

This grid is in an ASCX file and is part of a container page with other ASCX
controls.

My problem is that the user will select a couple of records to "Approve" and
click a Submit Button. On the Postback the grid is rebound with a fresh hit
to the database. If there are new records added to the database, the new
rows are added to the grid and everything shifts.

In my code behind I do something like this...

foreach( DataGridItem item in this.TimecardARGrid.Items )
{

// code deleted

// check box object for emp assign
CheckBox CheckedTimecard = (CheckBox)item.FindControl( "chkSelect" );

// see if the check box is checked
if ( CheckedTimecard.Checked )
{
// make a call to the databae

// A call to an Approval Function
// code deleted

// then uncheck the box
CheckedTimecard.Checked = false;

}

}


The problem is the new records added to the grid shifts the rows down, but
the checkbox controls that are checked are still in the original row (
always the row above ). Therefore, the wrong records gets "Approved".

When I change the code to rebind to a Session object, populated before the
postback from the Submit Button, the Checkbox controls are never "seen" as
checked. So why does a rebind of the grid from a Session DataView object
lose the checkbox state, but a rebind from a DataView generated from a
database call keep the Checkbox state and then finally, why does the
checkbox not move with the row when more records are added to the grid on
Postback.

Also, ViewState is turned off because this grid can be slow because of some
users have low bandwidth.

Any insight, suggestions, or examples would be greatly appreciated.

Thanx

Micah
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top