locked
LinkButtons not working on .aspx page when i add crystalreportviewer to page RRS feed

  • Question

  • User1018418207 posted

    HTML code

    <%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeBehind="liststudent.aspx.cs" Inherits="PublicSchoolMgt.admin.liststudent" %>

    <%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>

    <!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="AdminHome" runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
    <title>Frits High - School Management Software</title>

    <link rel="stylesheet" media="screen" href="../css/reset1.css" />
    <link rel="stylesheet" media="screen" href="../css/grid1.css" />
    <link rel="stylesheet" media="screen" href="../css/style1.css" />
    <link rel="stylesheet" media="screen" href="../css/messages1.css" />
    <link rel="stylesheet" media="screen" href="../css/forms1.css" />
    <link rel="stylesheet" media="screen" href="../css/tables1.css" />

    <!--[if lt IE 8]>
    <link rel="stylesheet" media="screen" href="css/ie.css" />
    <![endif]-->

    <!--[if lt IE 9]>
    <script type="text/javascript" src="js/html5.js"></script>
    <script type="text/javascript" src="js/PIE.js"></script>
    <script type="text/javascript" src="js/IE9.js"></script>
    <script type="text/javascript" src="js/excanvas.js"></script>
    <![endif]-->

    <!-- jquerytools -->
    <script type="text/javascript" src="../js1/jquery.tools.min.js"></script>
    <script type="text/javascript" src="../js1/jquery.cookie.js"></script>
    <script type="text/javascript" src="../js1/jquery.ui.min.js"></script>
    <script type="text/javascript" src="../js1/jquery.tables.js"></script>
    <script type="text/javascript" src="../js1/jquery.flot.js"></script>

    <script type="text/javascript" src="../js1/global.js"></script>

    <!-- THIS SHOULD COME LAST -->
    <!--[if lt IE 9]>
    <script type="text/javascript" src="js/ie.js"></script>
    <![endif]-->

    </head>
    <body>
    <form id="Form1" class="form" runat ="server">
    <div id="wrapper">
    <header>
    <div class="clearfix">
    <nav>
    <div class="avatar"><a href="home.aspx">
    <img src="../images/logo.png" alt="Logo" /></a></div>
    <div class = "clearfix">
    <asp:Label ID="Label2" runat="server" Text="" ForeColor="Green"></asp:Label>
    </div>
    <ul class="clearfix">
    <li>
    <asp:LinkButton ID="lnkSess" CssClass="arrow-down" Enabled="false" runat="server">New Session</asp:LinkButton>
    <ul>
    <li><asp:LinkButton ID="lnkPromo" runat="server" PostBackUrl="promoclass.aspx">Student Promotion</asp:LinkButton></li>
    <li><asp:LinkButton ID="lnkNewSess" runat="server" PostBackUrl="~/admin/session.aspx" >Create New Session</asp:LinkButton></li>
    </ul>
    </li>
    <li>
    <asp:LinkButton ID="lnkStaff" CssClass="arrow-down" Enabled="false" runat="server">Staff</asp:LinkButton>
    <ul>
    <li><asp:LinkButton ID="lnkTeachDetail" runat="server" PostBackUrl="teacherdetail.aspx">Add Staff/Teacher</asp:LinkButton></li>
    <li><asp:LinkButton ID="lnkAssSub" runat="server" PostBackUrl="assign.aspx">Assign Subject</asp:LinkButton></li>
    <li><asp:LinkButton ID="lnkTeachDelete" runat="server" PostBackUrl="teacherdelete.aspx">Manage Staff/Teacher</asp:LinkButton></li>
    </ul>
    </li>
    <li>
    <asp:LinkButton ID="lnkStudent" CssClass="arrow-down" Enabled="false" runat="server">Student</asp:LinkButton>
    <ul>
    <li><asp:LinkButton ID="lnkMassStudReg" runat="server" PostBackUrl="studentreg.aspx">Student Reg.(Mass)</asp:LinkButton></li>
    <li><asp:LinkButton ID="lnkStudReg" runat="server" PostBackUrl="studentdetail.aspx">Student Registration</asp:LinkButton></li>
    <li><asp:LinkButton ID="lnkStudList" runat="server" PostBackUrl="studlist.aspx">View Student List</asp:LinkButton></li>
    </ul>
    </li>
    <li>
    <asp:LinkButton ID="lnkResult" CssClass="arrow-down" Enabled="false" runat="server">Result & C.A.</asp:LinkButton>
    <ul>
    <li><asp:LinkButton ID="lnkBroadSheet" runat="server" PostBackUrl="broadsheet.aspx">Print Broadsheet</asp:LinkButton></li>
    <li><asp:LinkButton ID="lnkReport" runat="server" PostBackUrl="reportcard.aspx">Result Statement</asp:LinkButton></li>
    <li><asp:LinkButton ID="lnkPerformance" runat="server" PostBackUrl="~/admin/performance.aspx">Performance List</asp:LinkButton></li>
    </ul>
    </li>
    <li>
    <asp:LinkButton ID="lnkWeb" CssClass="arrow-down" Enabled="false" runat="server">Web Content</asp:LinkButton>
    <ul>
    <li><asp:LinkButton ID="lnkSlider" runat="server" PostBackUrl="slider.aspx">Web Slider</asp:LinkButton></li>
    <li><asp:LinkButton ID="lnkAdvert" runat="server" PostBackUrl="advertisements.aspx">Advert</asp:LinkButton></li>
    </ul>
    </li>
    <li>
    <asp:LinkButton ID="lnkUtil" CssClass="arrow-down" Enabled="false" runat="server">Utilities</asp:LinkButton>
    <ul>
    <li><asp:LinkButton ID="lnkAdmission" runat="server" PostBackUrl="admission.aspx">Admission List</asp:LinkButton></li>
    <li><asp:LinkButton ID="lnkTTable" runat="server" PostBackUrl="classtimetable.aspx">Time Table</asp:LinkButton></li>
    <li><asp:LinkButton ID="lnkGallery" runat="server" PostBackUrl="gallery.aspx">Gallery</asp:LinkButton></li>
    <li><asp:LinkButton ID="lnkMail" runat="server" PostBackUrl="sendmail.aspx">Messaging</asp:LinkButton></li>
    <li><asp:LinkButton ID="lnkSMS" runat="server" PostBackUrl="bulksms.aspx">Bulk SMS</asp:LinkButton></li>
    <li><asp:LinkButton ID="lnkTopGrad" runat="server" PostBackUrl="graduant.aspx">Top Graduants</asp:LinkButton></li>
    <li><asp:LinkButton ID="lnkNews" runat="server" PostBackUrl="news.aspx">News</asp:LinkButton></li>
    <li><asp:LinkButton ID="lnkEvents" runat="server" PostBackUrl="events.aspx">Events</asp:LinkButton></li>
    <li><asp:LinkButton ID="lnkVacancy" runat="server" PostBackUrl="vacancy.aspx">Vacancy</asp:LinkButton></li>
    </ul>
    </li>
    <li><asp:LinkButton ID="lnkAdmin" CssClass="arrow-down" Enabled="false" runat="server">Administrator</asp:LinkButton>
    <ul>
    <li><asp:LinkButton ID="lnkAcct" runat="server" PostBackUrl="account.aspx">New Account</asp:LinkButton></li>
    <li><asp:LinkButton ID="lnkManAccts" PostBackUrl="~/admin/manaccounts.aspx" runat="server" >Manage Accounts</asp:LinkButton></li>
    </ul>
    </li>
    <li class="fr active"><a class="arrow-down">My Account</a>
    <ul>
    <li><a href="accountedit.aspx">Edit Account</a></li>
    <li><a href="resetpassword.aspx" class="arrow-down">Change Password</a></li>
    <li><a href="logout.aspx">Sign out</a></li>
    </ul>
    </li>
    </ul>
    </nav>
    </div>
    </header>

    <section>
    <div class="container_8 clearfix">

    <!-- Main Section -->

    <section class="main-section grid_8">
    <!-- Sidebar Section -->
    <div class="main-content">
    <header><h2></h2></header>
    <header><h2></h2></header>
    <section class="container_6 clearfix">
    <div class="fr action">
    <a href="documentation/index.html" class="button button-orange help" rel="#overlay"><span class="help"></span>Help</a>
    </div>
    <div class="grid_4 clearfix">
    <header class="clearfix">

    <header>
    <h3>
    Students List - <asp:Label ID="Label3" runat="server" Text=""></asp:Label>
    </h3>
    </header>
    <div class = "clearfix">
    <asp:Label ID="Label1" runat="server" Text="" ForeColor="Red"></asp:Label>
    </div>
    <div class="clearfix">
    <asp:Button ID="btnPrint" runat="server" Width="120px"
    CssClass="button button-round" Text="Print List" onclick="btnPrint_Click"></asp:Button>
    </div>
    <div class="clearfix">
    <asp:GridView ID="GridView1" AutoGenerateColumns="False" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating"
    CssClass="datatable selectable full" runat="server" onpageindexchanging="GridView1_PageIndexChanging" PageSize="10">
    <PagerSettings Mode="NextPreviousFirstLast" />
    <Columns>
    <asp:TemplateField HeaderText="Student ID.">
    <ItemTemplate>
    <asp:Label runat="server" ID="StudentID" Text='<%#Eval("StudentID")%>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Last Name">
    <ItemTemplate>
    <asp:Label runat="server" ID="Lname" Text='<%#Eval("Lname")%>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="First Name">
    <ItemTemplate>
    <asp:Label runat="server" ID="Fname" Text='<%#Eval("Fname")%>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Middle Name">
    <ItemTemplate>
    <asp:Label runat="server" ID="Mname" Text='<%#Eval("Mname")%>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Sex">
    <ItemTemplate>
    <asp:Label runat="server" ID="Sex" Text='<%#Eval("Sex")%>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Date of Birth">
    <ItemTemplate>
    <asp:Label runat="server" ID="DOB" Text='<%#Eval("DOB")%>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Change Class">
    <ItemTemplate>
    <asp:Button ID="btnEdit" runat="server" Width="100px" Text="Change Class" CommandName="Edit"></asp:Button>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Edit">
    <ItemTemplate>
    <asp:Button ID="btnUpdate" runat="server" Width="100px" Text="Edit Profile" CommandName="Update"></asp:Button>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
    </div>
    </form>
    </section>
    </div>
    </section>
    </div>
    <!-- End Sidebar Section -->

    </section>

    <!-- Main Section End -->

    </div>
    </section>
    </div>
    <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />
    <footer>
    <div id="footer-inner" class="container_8 clearfix">
    <div class="grid_8">
    </div>
    </div>
    </footer>


    </body>
    </html>

    Code behind

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!Page.IsPostBack)
    {
    if (Session["AdminID"] == null)
    {
    Response.Redirect(@"/admin/logout.aspx");
    }

    if (User.IsInRole("admin"))
    {
    lnkNewSess.Enabled = false;
    lnkPromo.Enabled = false;
    lnkTeachDetail.Enabled = false;
    lnkTeachDelete.Enabled = false;
    lnkSMS.Enabled = false;
    lnkAcct.Enabled = false;
    lnkManAccts.Enabled = false;
    }
    else if (User.IsInRole("administrator"))
    {
    lnkNewSess.Enabled = true;
    lnkPromo.Enabled = true;
    lnkTeachDetail.Enabled = true;
    lnkTeachDelete.Enabled = true;
    lnkSMS.Enabled = true;
    lnkAcct.Enabled = true;
    lnkManAccts.Enabled = true;
    lnkAssSub.Enabled = true;
    }
    else
    {
    Response.Redirect(@"/admin/logout.aspx");
    }
    }
    getName();
    gridbind();
    getclassname();
    Response.Cache.SetNoStore();
    }

    private void getName()
    {
    int AdminID = int.Parse(Session["AdminID"].ToString());
    string Username = getUsername(AdminID);
    Label2.Text = "Welcome, " + Username + "!";
    }

    public static string getUsername(int AdminID)
    {
    PublicSchoolMgt.admin.liststudent list = new liststudent();
    using (SqlConnection con = new SqlConnection(list.CS))
    {
    string msg;
    DataSet ds = new DataSet();
    SqlDataAdapter da = new SqlDataAdapter("sp_Admin", con);
    da.SelectCommand.CommandType = CommandType.StoredProcedure;
    da.SelectCommand.Parameters.AddWithValue("@Admin_Id", AdminID);
    da.SelectCommand.Parameters.AddWithValue("@Type", "s");
    da.Fill(ds);
    con.Open();
    if (ds.Tables[0].Rows.Count > 0)
    {
    msg = ds.Tables[0].Rows[0]["Fullname"].ToString();
    }
    else
    {
    msg = null;
    }
    return msg;
    }
    }

    public static int getSession()
    {
    PublicSchoolMgt.admin.liststudent list = new liststudent();
    using (SqlConnection con = new SqlConnection(list.CS))
    {
    int code;
    DataSet ds = new DataSet();
    SqlDataAdapter da = new SqlDataAdapter("sp_Session", con);
    da.SelectCommand.CommandType = CommandType.StoredProcedure;
    da.SelectCommand.Parameters.AddWithValue("@Type", "b");
    da.Fill(ds);
    con.Open();
    if (ds.Tables[0].Rows.Count > 0)
    {
    code = int.Parse(ds.Tables[0].Rows[0]["SessID"].ToString());
    }
    else
    {
    code = 0;
    }
    return code;
    }
    }

    public static DataSet getStudent(int ClassID, int SessID)
    {
    PublicSchoolMgt.admin.liststudent list = new liststudent();
    using (SqlConnection con = new SqlConnection(list.CS))
    {
    DataSet ds = new DataSet();
    SqlDataAdapter da = new SqlDataAdapter("sp_StudentDetail", con);
    da.SelectCommand.CommandType = CommandType.StoredProcedure;
    da.SelectCommand.Parameters.AddWithValue("ClassID", ClassID);
    da.SelectCommand.Parameters.AddWithValue("SessID", SessID);
    da.SelectCommand.Parameters.AddWithValue("@Type", "k");

    da.Fill(ds);
    con.Open();

    try
    {
    return ds;
    }
    catch
    {
    throw;
    }
    finally
    {
    con.Close();
    }
    }
    }

    public static string getclasslink(int ClassID)
    {
    PublicSchoolMgt.admin.liststudent list = new liststudent();
    using (SqlConnection con = new SqlConnection(list.CS))
    {
    string msg;
    DataSet ds = new DataSet();
    SqlDataAdapter da = new SqlDataAdapter("sp_Class", con);
    da.SelectCommand.CommandType = CommandType.StoredProcedure;
    da.SelectCommand.Parameters.AddWithValue("@ClassID", ClassID);
    da.SelectCommand.Parameters.AddWithValue("@Type", "j");
    da.Fill(ds);
    con.Open();
    if (ds.Tables[0].Rows.Count > 0)
    {
    msg = ds.Tables[0].Rows[0]["Classlink"].ToString();
    }
    else
    {
    msg = "";
    }
    return msg;
    }
    }

    private void getclassname()
    {
    int classid = int.Parse(Session["ClassID"].ToString());
    string classlink = getclasslink(classid);
    Label3.Text = classlink;
    }

    public void gridbind()
    {
    int ClassID = int.Parse(Session["ClassID"].ToString());
    int SessID = getSession();
    DataSet ds = getStudent(ClassID, SessID);
    if (ds.Tables[0].Rows.Count > 0)
    {
    GridView1.DataSource = ds.Tables[0].DefaultView;
    GridView1.DataBind();
    }
    else
    {
    Label1.Text = "No students records found!";
    }
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
    GridView1.PageIndex = e.NewPageIndex;
    gridbind();
    }

    protected void btnPrint_Click(object sender, EventArgs e)
    {
    int SessID = getSession();
    Session["SessID"] = SessID;

    int ClassID = int.Parse(Session["ClassID"].ToString());
    Session["ClassID"] = ClassID;

    DataSet ds = new DataSet();
    ds = getStudent(ClassID, SessID);
    //SchoolMgt.print.studlist stdlist = new SchoolMgt.print.studlist();
    if (ds.Tables[0].Rows.Count > 0)
    {
    // Once I have the data I need to apply it to the connection of the report
    //code to request connection using connectionString in web.config
    PublicSchoolMgt.admin.liststudent list = new liststudent();
    SqlConnectionStringBuilder sqlconn = new SqlConnectionStringBuilder(list.CS);

    ConnectionInfo crConnection = new ConnectionInfo();
    crConnection.UserID = sqlconn.UserID;
    crConnection.ServerName = sqlconn.DataSource;
    crConnection.DatabaseName = sqlconn.InitialCatalog;
    crConnection.Password = sqlconn.Password;

    ReportDocument stdlist = new ReportDocument();
    stdlist.Load(Server.MapPath("~/print/studlist.rpt")); // path of report

    Tables rptTables = stdlist.Database.Tables;
    for (int i = 0; i < rptTables.Count; i++)
    {
    CrystalDecisions.CrystalReports.Engine.Table tblRpt = rptTables[i];
    TableLogOnInfo tblInfo = tblRpt.LogOnInfo;
    tblInfo.ConnectionInfo = crConnection;
    tblRpt.ApplyLogOnInfo(tblInfo);
    }
    stdlist.SetParameterValue("paraSessID", int.Parse(Session["SessID"].ToString()));
    stdlist.SetParameterValue("paraClassID", int.Parse(Session["ClassID"].ToString()));

    CrystalReportViewer1.ReportSource = stdlist;
    Session["SessID"] = null;
    Session["ClassID"] = null;

    stdlist.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, true, "First Term Broadsheeet");
    //here i have used [ CrystalDecisions.Shared.ExportFormatType.PortableDocFormat ] to Export in PDF
    }
    else
    {
    Label1.Text = "No student records found!";
    }
    }

    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
    Label ID = GridView1.Rows[e.NewEditIndex].FindControl("StudentID") as Label;
    int StudentID = int.Parse(ID.Text);

    Session["StudentID"] = StudentID;

    Response.Redirect(@"newstudentclass.aspx");
    }

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
    Label ID = GridView1.Rows[e.RowIndex].FindControl("StudentID") as Label;
    int StudentID = int.Parse(ID.Text);

    Session["StudentID"] = StudentID;
    Response.Redirect(@"studentedit.aspx");
    }

    Tuesday, February 7, 2017 3:29 PM

All replies

  • User-1509636757 posted

    Can you provide some more detail on what you mean by "LinkButton not working"

    Tuesday, February 7, 2017 4:37 PM