We help IT Professionals succeed at work.

Task needed help! ASP.Net c#

205 Views
Last Modified: 2013-12-17
Hi,

I would like to know if it will be possible to do the following in asp.net using c# as background code.

- The user will be asked to select which fields he wants to be visible from a list that comprises all the fields
- The user should be able to save the fields selected as a template view.
- Once in the report, the user should be able to filter on the visible columns.

This is all regrading when user is viewing the results in a table. I am currently using MS Access as my database. I feel this should be possible using a gridview.

Any help will be appreciated.

Regards,

introlux
Comment
Watch Question

Developer User Interface
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
introluxTechincal Director

Author

Commented:
I am not sure how I will go around to program this. As I have not done this type of command I am not sure.

Is there any form of sample code you can assist of helping please.

Regards,

introlux
Obadiah ChristopherDeveloper User Interface
CERTIFIED EXPERT

Commented:
Any code u have written till now for the same?
introluxTechincal Director

Author

Commented:
I have provided my front and back code.

Any help will be appreciated.

Regards,

introlux
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="testFilter.aspx.cs" Inherits="testFilter" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/Data/ProCom.mdb" SelectCommand="SELECT [PName], [ICD_IDF], [PType], [CName] FROM [tblProCom] WHERE [PName] <> 'select'">
</asp:AccessDataSource>
        <br />
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Reset Filters" /><br />
        <br />
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        CellPadding="4" DataSourceID="AccessDataSource1"
        ForeColor="#333333" GridLines="None"
        AllowPaging="True" OnPageIndexChanged="GridView1_PageIndexChanged">
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <Columns>
                <asp:BoundField DataField="PName" HeaderText="PName" SortExpression="PName" />
                <asp:BoundField DataField="ICD_IDF" HeaderText="ICD_IDF" SortExpression="ICD_IDF" />
                <asp:TemplateField HeaderText="ProjectType" SortExpression="PType">
                <HeaderTemplate>
                Project Type
                <asp:DropDownList ID="ddPType"  
                DataTextField="PType"
                AutoPostBack="true"
                OnSelectedIndexChanged="FilterDropDown_IndexChanged"
                OnPreRender="SetValue"
                DataSourceID="AccessDataSource2" runat="server" AppendDataBoundItems="True">
                    <asp:ListItem>Please select</asp:ListItem>
                </asp:DropDownList>
                </HeaderTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("PType") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("PType") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="CName" HeaderText="CName" SortExpression="CName" />
            </Columns>
            <RowStyle BackColor="#EFF3FB" />
            <EditRowStyle BackColor="#2461BF" />
         <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
         <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
        <br />
        <br />
        &nbsp;<br />
        <asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/Data/ProCom.mdb"
            SelectCommand="SELECT DISTINCT PType FROM tblProCom">
        </asp:AccessDataSource>
        </div>
    </form>
</body>
</html>
 
 
========================================================================
 
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
 
public partial class testFilter : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
 
    protected void FilterDropDown_IndexChanged(object sender, EventArgs e)
    {
        DropDownList dd = (DropDownList)sender;
        ViewState["SelectedValue"] = dd.SelectedValue;
        this.AccessDataSource1.SelectCommand = "SELECT [PName], [ICD_IDF], [PType], [CName] FROM [tblProCom] WHERE [PName] <> 'select' AND [PType]='" + dd.SelectedValue + "'";
        GridView1.DataBind();
    }
 
    protected void SetValue(object sender, EventArgs e)
    {
        if (ViewState["SelectedValue"] != null)
        {
            DropDownList ddl = (DropDownList)sender;
            ddl.SelectedValue = ViewState["SelectedValue"].ToString();
        }
    }
 
    protected void GridView1_PageIndexChanged(object sender, EventArgs e)
    {
 
    }
 
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("testFilter.aspx");
    }
}

Open in new window

introluxTechincal Director

Author

Commented:
????????
introluxTechincal Director

Author

Commented:
Helped guiding me to right direction.

Thanks

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.