Click here to Skip to main content
12,071,956 members (57,929 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
hi here some problem with refreshing grid.its not taking me to second page when i click page2

protected void Search_Click(object sender, ImageClickEventArgs e)
   {
 

       SearchFacultyPL stPL = new SearchFacultyPL();
       stPL.eSession = ddlSession.SelectedValue;
       stPL.ExamDate = ddlDate.SelectedValue;
       stPL.RoomNo = ddlSemister.SelectedValue;
 

       SearchFacultyBLL stBLL = new SearchFacultyBLL();
       DataTable dt = new DataTable();
       dt = stBLL.SearchRoomDetails(stPL);
 
       if (dt.Rows.Count > 0)
       {
          grdTimeTable.DataSource = dt;
           grdTimeTable.DataBind();
       }
 

       if (connection.State == ConnectionState.Open)
       {
           connection.Close();
       }
       connection.Open();
       SqlCommand cmd5 = new SqlCommand();
       SqlDataReader dr5;
       cmd5.Connection = connection;
       cmd5.CommandText = "select facultycode from fAllotmentTab where RoomNo='" + ddlSemister.SelectedValue + "' and examdate='" + ddlDate.SelectedValue + "' and esession='" + ddlSession.SelectedValue + "'";
       dr5 = cmd5.ExecuteReader();
       //if (dr5.Read())
       //{
       //    labelmsg.Text = "Alloted Faculty : " + dr5.GetValue(0).ToString();
       //}
       //else { labelmsg.Text = "Alloted Faculty : "; }
       labelmsg.Text = (dr5.Read()) ? "Alloted Faculty : " + dr5.GetValue(0).ToString() : "Alloted Faculty : ";
 
   }
   protected void grdTimeTable_PageIndexChanging(object sender, GridViewPageEventArgs e)
   {
       grdTimeTable.PageIndex = e.NewPageIndex;
 
       DisplayPage();
   }
   void DisplayPage()
   {
       int CurrentPage = grdTimeTable.PageIndex + 1;
   }

can any one tell me how to bind grid.here m not using in page load..
Posted 6-Mar-12 2:01am
ythisbug2.1K

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

first
if (connection.State == ConnectionState.Open)
        {
            connection.Close();
        }
        connection.Open();

change to

if (connection.State != ConnectionState.Open)
        {
            connection.Open();
        }

second
SqlCommand cmd5 = new SqlCommand();
        SqlDataReader dr5;
        cmd5.Connection = connection;
        cmd5.CommandText = "select facultycode from fAllotmentTab where RoomNo='" + ddlSemister.SelectedValue + "' and examdate='" + ddlDate.SelectedValue + "' and esession='" + ddlSession.SelectedValue + "'";

to

string selecttext = "select facultycode from fAllotmentTab where RoomNo=@RoomNo and examdate=@ExamDate and esession=@Session";
SqlCommand cmd5 = new SqlCommand(selecttext, connection);
cmd5.parameters.add("@RoomNo"ddlSemister.SelectedValue);
cmd5.parameters.add("@ExamDate", ddlDate.SelectedValue);
cmd5.parameters.add("@Session", ddlSession.SelectedValue);

There could be more optimizations in code but these things were absolute blunders so i pointed them.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160208.1 | Last Updated 6 Mar 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100