Click here to Skip to main content
11,705,451 members (59,951 online)
Rate this: bad
good
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 1: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
0 Sergey Alexandrovich Kryukov 500
1 OriginalGriff 269
2 CPallini 82
3 ppolymorphe 68
4 Inimicos 60
0 OriginalGriff 9,053
1 Sergey Alexandrovich Kryukov 8,347
2 CPallini 5,189
3 Maciej Los 4,726
4 Mika Wendelius 3,626


Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 6 Mar 2012
Copyright © CodeProject, 1999-2015
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