Click here to Skip to main content
15,894,291 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

1 solution

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


change to

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


second
SQL
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

C#
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900