Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 How to use a checkbox for datagrid results

Author  Topic 

prk72
Starting Member

1 Post

Posted - 2007-07-26 : 13:34:40
I'm having a VERY difficult time trying to get this to work, I hope someone in the forum can help.

Basically I have 3 columns in my database which are ID, Name, and Status. I would like to show results in my datagrid that are filtered by checkboxes. I had someone start to help in another forum but haven't heard back and am now lost. This is what I've done so far:

SQL Statement:

SELECT TaskId, Name, Status
FROM Tasks
WHERE (Status = 'Pending') AND (@ShowPending = 1) OR
(Status = 'Active') AND (@ShowActive = 1) OR
(Status = 'ReAssign') AND (@ShowReAssign = 1) OR
(Status = 'Completed') AND (@ShowCompleted = 1)

I have the DbType set to Boolean in the collection parameters.

This is my VB code:


<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Default" title="Untitled Page" %>


<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<table class="status">
<tr>
<td>Show active tasks</td>
<td><asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" /></td>
</tr>
<tr>
<td>Show completed tasks</td>
<td><asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="True" /></td>
</tr>
<tr>
<td>Show reassigned tasks</td>
<td><asp:CheckBox ID="CheckBox3" runat="server" AutoPostBack="True" /></td>
</tr>
<tr>
<td>Show pending tasks</td>
<td><asp:CheckBox ID="CheckBox4" runat="server" AutoPostBack="True" /></td>
</tr>



</table>
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<div class="progress"><img src="images/indicator.gif" />Updating ...</div>
</ProgressTemplate>
</asp:UpdateProgress>


<div class="ToDoHeader" style="font-size: 18px; color: #cc0033; font-family: Broadway">ToDo List Items</div>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True"
AutoGenerateColumns="False"
DataKeyNames="TaskId"
DataSourceID="ObjectDataSource1"
CssClass="gridview"
AlternatingRowStyle-CssClass="even"
Gridlines="None">
<Columns>
<asp:CommandField ShowEditButton="True" >
<ItemStyle HorizontalAlign="Center" />
</asp:CommandField>
<asp:BoundField DataField="TaskId" HeaderText="TaskId" InsertVisible="False" ReadOnly="True" SortExpression="TaskId" >
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
<FooterStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" >
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:CheckBoxField DataField="Status" HeaderText="Status" SortExpression="Status" >
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:CheckBoxField>
</Columns>
<AlternatingRowStyle CssClass="even" />
</asp:GridView>


</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="CheckBox1" EventName="CheckedChanged" />
<asp:AsyncPostBackTrigger ControlID="CheckBox2" EventName="CheckedChanged" />
<asp:AsyncPostBackTrigger ControlID="CheckBox3" EventName="CheckedChanged" />
<asp:AsyncPostBackTrigger ControlID="CheckBox4" EventName="CheckedChanged" />
</Triggers>

</asp:UpdatePanel>

<div class="insertheader">Add a New Task</div>

<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="TaskId"
DataSourceID="ObjectDataSource1"
DefaultMode="Insert"
CssClass="detailsview"
Gridlines="None">
<Fields>
<asp:BoundField DataField="TaskId" HeaderText="TaskId" InsertVisible="False" ReadOnly="True" SortExpression="TaskId" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:CheckBoxField DataField="Status" HeaderText="Active" SortExpression="Status" />
<asp:CheckBoxField DataField="Status" HeaderText="Completed" SortExpression="Status" />
<asp:CheckBoxField DataField="Status" HeaderText="ReAssigned" SortExpression="Status" />
<asp:CheckBoxField DataField="Status" HeaderText="Pending" SortExpression="Status" />
<asp:CommandField ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
</ContentTemplate>
</asp:UpdatePanel>

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DeleteMethod="Delete"
InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetTasksByActiveComplete"
TypeName="TasksDataSetTableAdapters.TasksTableAdapter"
UpdateMethod="Update">
<DeleteParameters>
<asp:Parameter Name="Original_TaskId" Type="Int32" />
</DeleteParameters>

<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Status" Type="Boolean" />
<asp:Parameter Name="Original_TaskId" Type="Int32" />
</UpdateParameters>

<SelectParameters>
<asp:ControlParameter ControlID="CheckBox1" Name="ShowActive" PropertyName="Checked" Type="Boolean" />
<asp:ControlParameter ControlID="CheckBox2" Name="ShowComplete" PropertyName="Checked" Type="Boolean" />
<asp:ControlParameter ControlID="CheckBox3" Name="ShowReAssigned" PropertyName="Checked" Type="Boolean" />
<asp:ControlParameter ControlID="CheckBox4" Name="ShowPending" PropertyName="Checked" Type="Boolean" />
</SelectParameters>

<InsertParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Status" Type="Boolean" />
</InsertParameters>

</asp:ObjectDataSource>
</asp:Content>


I do so hope someone can help. Thanks in advance.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-07-26 : 13:39:35
Moving this thread to the .NET forums since this is a programming question.

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -