Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > ASP.NET 1.x and 2.0 Application Design
|
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 27th, 2003, 02:28 PM
Authorized User
 
Join Date: Aug 2003
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default rebinding checkbox checks in a template column

Hi,

I have two template columns in my datagrid, code for which I have put in the html page like so:

<columns>
<asp:TemplateColumn HeaderText="Assigned">
 <ItemTemplate>
  <asp:CheckBox ID="cbAssigned" Runat="server"
  Checked = '<%#DataBinder.Eval(Container.DataItem,"IsAssigned ")%>' Enabled="False" />
 </ItemTemplate>
  </asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Reassign">
 <ItemTemplate>
  <asp:LinkButton ID="Reassign" text="Reassign"
   CommandName="Reassign" Runat="server" />
 </ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="LoginName" HeaderText="LoginName">
 <HeaderStyle ForeColor="White" BackColor="Maroon"></HeaderStyle>
 <ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
</columns>

The first template column has checkboxes, which binds to a column in datasource, as in the code above.

Second template column has asp:linkbuttons, pressing which calls a function called Reassign, which I have defined in my VB.NET codebehind.
After the page loads, I press a button called search, which gets the info from the database and binds the grid to the datasource. At that time, I can see my appropriate checkboxes checked.

When I click the "reassign" link in a row, I make some changes to the datasource, update the database and rebind the grid to the source. When the page loads again, I can see changes in all the appropriate boundcolumns (including the one that I show above in the code), but not in the checkboxes.

What am I missing? As you might expect, page_load is called before the reassign event is fired. Why should databind bind only a few columns?

Any input will be appreciated.
 
Old August 27th, 2003, 03:17 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

This is how it usually works with datagrid events:

In page_load() you have something like this:
Code:
If Not IsPostBack Then
    BindMyDataGrid()
End If
Then you have this function:
Code:
Private Sub BindMyDataGrid()
    'Do data retrieval and bind to grid here
End Sub
Any event that results in data changes needs to call BindMyDataGrid(). In your example your have a link button that calls Reassign() so...
Code:
Private Sub Reassign()
    'Do reassign code here
    BindMyDataGrid()
End Sub
It looks like you are doing something like this from your description above. Even if the bind code is running all the time in Page_load (not conditional based on IsPostback) then there's still little reason for you to be seeing errors.
 
Old August 27th, 2003, 03:34 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I'm sitting here staring at your original post and realizing that my post probably was useless. I can't begin to imagine why you'd only get partial grid updates. If you rebind the thing, everything should update. Your checkbox "checked" bind code looks good and it's obviously working (somewhat). Check your data, make sure everything's being updated that you want to update.

Does this only happen when you are in the viewstate lifespan of that page? If you leave the page and load the page fresh is all the data in the grid representative of whats in the DB? At one point I thought that maybe the postback was causing the checkboxes to do strange things, but I can't imagine that being the problem. I know I've used disabled checkboxes before on a grid to show a status like you are doing, but I can't say I am updating items in the list then rebind like you are so I haven't seen this occurence.

Got me baffled.
 
Old August 27th, 2003, 04:53 PM
Authorized User
 
Join Date: Aug 2003
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I just realized something. My checkboxes are getting their data from a column whose value depends on a case statement in the stored procedure.

When I do the rebind in reassign procedure, the data in that column hasn't changed. However, the condition has changed, and the next time I retrieve data from the database, I get updated values in that column, and I see my checkboxes checked appropriately.

I think you are right. It's the data that my checkboxes are binding to.

cheers :-)
 
Old October 22nd, 2006, 06:16 PM
Registered User
 
Join Date: Feb 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Texas Raven, you seem to be working on the AS400 in the area I have been struggling with for over 6 months. Can you please contact me to see if you have solved the problem I am can not seem to solve.

Thanks
JesseH
hernandj@eim-co.com






Similar Threads
Thread Thread Starter Forum Replies Last Post
template column in datagrid p2pMember ASP.NET 1.0 and 1.1 Basics 1 November 18th, 2005 06:33 PM
saving checkbox state in template column texasraven ASP.NET 1.x and 2.0 Application Design 7 September 28th, 2005 01:18 PM
Template Column - question vox ASP.NET 1.0 and 1.1 Basics 2 June 7th, 2005 11:53 AM
Checkbox Column ncminhtung BOOK: ASP.NET Website Programming Problem-Design-Solution 1 April 20th, 2005 07:08 AM
template column and bound column hidayah ASP.NET 1.x and 2.0 Application Design 1 April 9th, 2005 03:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.