R
r.hein
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<Info> SortList(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.
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<Info> SortList(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.