473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Gridview bound to Object and Checkbox

I've got a middle tier data object that I'm binding a gridview to, and
I'm having some problems with the check box, and having it enabled.

Let'd start with the middle tier object (and the corresponding
collection). The object is simple - it's got some properties (only one
has a setter), and a constructor.
public class Info
{
private int _ID;
private DateTime _createDate;
private int _Age;
private bool _selected;

public int ID
{
get
{
return ID;
}
}
public DateTime CreateDate
{
get
{
return _createDate;
}
}
public int Age
{
get
{
return _Age;
}
}
public bool Selected
{
get
{
return _selected;
}
set
{
_selected = value;
}
}
public Info( int ID, DateTime CreateDate, int Age)
{
_ID = ID;
_createDate = CreateDate;
_Age = Age;
_selected = false;
}

}

There's also an object InfoList that inherits from the generic list
List<Info>, basically what happens is that in it's constuctor it walks
a dataset from another object and populates itself with Info objects

public class InfoList:List<Info>
{

public InfoList():this((true))
{
}
public InfoList(bool LoadDefaultData)
{

if (LoadDefaultData)
{
InfoBase baseDS = new InfoBase();
DataTable tempTable = baseDS.Tables[0];
foreach (DataRow tempRow in tempTable.Rows)
{
Info tempInfo = new
Info(Convert.ToInt32(tempRow["ID"])
,
Convert.ToDateTime(tempRow["CreateDate"])
,
Convert.ToInt32(tempRow["Age"]));

this.Add(tempInfo);
}
}
}
public List<InfoSortList(int maximumRows, int startRowIndex,
string SortExpression){
// Code left out for brevity, this is the Select method used
by the gridview
}
public int GetCount(){
return this.Count;
}
}

Here's the Gridview code

<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False"
DataSourceID="UnsoldInventory" Width="725px" CellPadding="0"
BorderWidth="0px"
AllowSorting="True" PageSize="10"
EnableSortingAndPagingCallbacks="True"
EnableViewState="False" HorizontalAlign="Left" ShowFooter="True">
<Columns>
<asp:CheckBoxField DataField="Selected" Text="Buy Now!" >
<ItemStyle CssClass="bt" HorizontalAlign="Center" />
</asp:CheckBoxField>
<asp:BoundField DataField="ID" Visible="false">
<ItemStyle CssClass="bt" HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="CreateDate" HeaderText="Create Date"
SortExpression="CreateDate" ReadOnly="True" >
<ItemStyle CssClass="bt" HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Age" HeaderText="Create Date"
SortExpression="Age" ReadOnly="True" >
<ItemStyle CssClass="bt" HorizontalAlign="Center" />
</asp:BoundField>
</Columns>
<RowStyle BackColor="White" />
<HeaderStyle CssClass="ftt" HorizontalAlign="Center" />
<SelectedRowStyle ForeColor="Red" Font-Bold="False"
BackColor="#BBBBBB"></SelectedRowStyle>
<AlternatingRowStyle BackColor="#EDEDED" />
<PagerSettings Mode="NumericFirstLast" Position="TopAndBottom" />
<PagerStyle ForeColor="Black" HorizontalAlign="Right"
BackColor="#C6C3C5" />
</asp:GridView>
<%--<i>You are viewing page
<%=GridView1.PageIndex + 1%>
of
<%=GridView1.PageCount%>
</i>--%>
<asp:ObjectDataSource ID="UnsoldInventory" runat="server"
SelectMethod="SortList"
TypeName="InfoList" EnablePaging="true"
SortParameterName="SortExpression" SelectCountMethod="getCount" >
</asp:ObjectDataSource>

So my question is this: I need the check boxes tied to the Selected
property of the Info object to be able to be checked and unchecked, so
I can know which items the end user wants. I don't want to have to have
the user edit one row at a time, and I've got
EnableSortingAndPagingCallbacks="True" on which prevents me from using
a template - I get an error message about Templates not being supported
- If I turn off the EnableSortingAndPagingCallbacks then the paging and
sorting quits working.

I've been unable to find an example for doing this, I find it hard to
beleive that no one at MS thought people would want this functionality.
BTW this is .NET 2.0 if that matters.

Any ideas?

Thanks.

Dec 6 '06 #1
3 6570
Pao

r.****@wavecable.com wrote:
So my question is this: I need the check boxes tied to the Selected
property of the Info object to be able to be checked and unchecked, so
I can know which items the end user wants.
I've been unable to find an example for doing this, I find it hard to
beleive that no one at MS thought people would want this functionality.
BTW this is .NET 2.0 if that matters.

Any ideas?

Thanks.
Well I have the same problem; I tried the Itemtemplate but throws a
invalid cast exception, then I tried to change the property of my
object from bool to int, but nothing to do.

Really anyone knows how to get around?

Jan 1 '07 #2
Pao

r.****@wavecable.com wrote:
So my question is this: I need the check boxes tied to the Selected
property of the Info object to be able to be checked and unchecked, so
I can know which items the end user wants. I don't want to have to have
the user edit one row at a time, and I've got
EnableSortingAndPagingCallbacks="True" on which prevents me from using
a template - I get an error message about Templates not being supported
- If I turn off the EnableSortingAndPagingCallbacks then the paging and
sorting quits working.

I've been unable to find an example for doing this, I find it hard to
beleive that no one at MS thought people would want this functionality.
BTW this is .NET 2.0 if that matters.

Any ideas?

Thanks.

Same problem.
Really anyone knows how to solve? documentation is really poor...
I get the error that the value of the checkbox
"could not be parsed as a boolean"
but I tried also to change from Bool to Int the property of my business
object.

Jan 1 '07 #3
Pao

Pao wrote:
Same problem.
Really anyone knows how to solve? documentation is really poor...
I get the error that the value of the checkbox
"could not be parsed as a boolean"
but I tried also to change from Bool to Int the property of my business
object.

I found the solution
As I operate with MySql, simply putting the boolean field as
ENUM('True','False') default 'False', permit the <asp:CheckBoxField to
bind correctly.

Jan 3 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
4
by: Jim Katz | last post by:
I have an application that updates a strongly typed data set at run time. I'd like to dynamically create a table that connects to a run time data table. For displaying the data, this works well. ...
3
by: Mike P | last post by:
When I am performing a command on a row in my gridview, it works fine, unless I have paging enabled and I try t execute the command on a page other than the first page. The error I get is 'Index...
9
by: mike7510uk | last post by:
Hi, I am using a gridview with a templatefield containing a checkbox. I want to update the database with a 1 or 0 depending on if a checkbox is checked or unchecked (then use the 1 or 0 later on...
8
by: gerry | last post by:
The PagerSettings.Visible property is not being handled properly by the GridView control. The value assigned to this property is not applied until after a postback. Simplest test : .aspx...
1
by: Neven Klofutar | last post by:
Hi, I have a questin regarding GridView, Template column and Checkbox in it. I'm working on a project that has several "client" applications entering data into DB, and one "admin" application...
12
by: dixonjm | last post by:
Hi, I am new to gridviews, so any help would be most appreciated. Here is my problem:- I have a form with a GridView and a button. My gridview is bound to a collection (12000 items) (PageSize...
1
by: =?Utf-8?B?U2hhdw==?= | last post by:
I have a small GridView about max 10 rows and few columns. The columns are simple just a checkbox and a textbox and a bound name. The users don’t want to click “edit” button to edit and...
3
by: =?Utf-8?B?Um9iZXJ0IFNtaXRo?= | last post by:
Hi, I have a GridView with a checkbox column in it called FromInsight, however this is not bound to the dataset, its value is based on another column from the dataset called sourceid For each...
1
BeemerBiker
by: BeemerBiker | last post by:
I converted an arraylist to a dataset and bound the dataset to a gridview but I cannot change the value of the checkbox in the gridview. I identified the DataKeyNames and made sure that ReadOnly was...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.