Click here to Skip to main content
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 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
0 OriginalGriff 200
1 PIEBALDconsult 150
2 BillWoodruff 148
3 Jochen Arndt 135
4 DamithSL 130
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 6 Mar 2012
Copyright © CodeProject, 1999-2014
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