Gridview. databind is not working..

Last post 05-09-2008 9:27 AM by suchitranayak. 4 replies.

Sort Posts:

  • Gridview. databind is not working..

    05-09-2008, 8:27 AM

    using System;

    using System.Data;

    using System.Configuration;

    using System.Collections;

    using System.Web;

    using System.Web.Security;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    using System.Web.UI.WebControls.WebParts;

    using System.Web.UI.HtmlControls;

    public partial class Transaction_F_EMP_TransferView : System.Web.UI.Page

    {

    bool page_allow = false;

    bool apprv_transfer = false;

    bool transfer_emp = false;

    bool transfer_view = false;

    bool tran_reqemp = false;

    bool tran_reqhod = false;

    string comma_FnID;long ReqstrID = 0;

     

     

    protected void Page_Load(object sender, EventArgs e)

    {

     

    if (!IsPostBack)

    {

    # region Code for checking the permission of the user based on functionality

    try

    {

    btnfilter.Visible =
    false;

    clsEnumFunctionality function = new clsEnumFunctionality();

    apprv_transfer = function.IsAccessAllowed((int)clsEnumFunctionality.Functionality.ApprovingTransferRequest);

    transfer_emp = function.IsAccessAllowed((int)clsEnumFunctionality.Functionality.TransferringEmployee);

    transfer_view = function.IsAccessAllowed((int)clsEnumFunctionality.Functionality.ViewingAllTransferRequests);

    tran_reqemp = function.IsAccessAllowed((int)clsEnumFunctionality.Functionality.RequestTransferOfANormalEmployee);

    tran_reqhod = function.IsAccessAllowed((int)clsEnumFunctionality.Functionality.RequestingTransferOfHOD);

     

    if (apprv_transfer || transfer_emp || transfer_view || tran_reqemp ||tran_reqhod)

    page_allow = true;

    place_hold_viewtrans.Visible = true;

    comma_FnID = "";

    if (apprv_transfer)

    comma_FnID = comma_FnID + ((int)clsEnumFunctionality.Functionality.ApprovingTransferRequest).ToString() + ",";

    if (transfer_emp)

    comma_FnID = comma_FnID + ((int)clsEnumFunctionality.Functionality.TransferringEmployee).ToString() + ",";

    if (transfer_view)

    comma_FnID = comma_FnID + ((int)clsEnumFunctionality.Functionality.ViewingAllTransferRequests).ToString()+ ",";

    if (tran_reqemp)

    comma_FnID = comma_FnID + ((int)clsEnumFunctionality.Functionality.RequestTransferOfANormalEmployee).ToString() + ",";

    if (tran_reqhod)

    comma_FnID = comma_FnID + ((int)clsEnumFunctionality.Functionality.RequestingTransferOfHOD).ToString();

    if (page_allow == false)

    {

    place_hold_viewtrans.Visible =
    false;lblError.Text = "<b> YOU DONT HAVE THE PERMISSION FOR VIEW THIS PAGE </b>";

    }

    }

    catch (Exception ex) { Response.Redirect(ConfigurationSettings.AppSettings["PAGE_HOST"] + "Home.aspx", false); }

    # endregion

    if (page_allow == true)

    {

     

    if (apprv_transfer == true || transfer_emp == true || transfer_view == true || tran_reqemp == true || tran_reqhod == true )btnfilter.Visible = true;

     

     

    clsSqlDAL_TransferEmployee objdept = new clsSqlDAL_TransferEmployee();

    DataTable UserCntxts = new DataTable();

    long in_UserID = Convert.ToInt64(Session["UserID"].ToString());

    UserCntxts = objdept.GetCntxtUsersForFnIDs(in_UserID, comma_FnID);

    drop_constsnt.DataSource = UserCntxts;

    drop_constsnt.DataValueField =
    "EmpID";drop_constsnt.DataTextField = "EmpName";

    drop_constsnt.DataBind();

    long emp_id = Convert.ToInt64(Session["EmpID"].ToString());

    if (drop_constsnt.Items.Count == 2)

    {

    if (drop_constsnt.Items[1].Value.Equals(emp_id.ToString()))

    drop_constsnt.Visible = false;

    Label2.Visible = false;DataSet dsdrop = new DataSet();

    dsdrop = objdept.GetRequesterName(emp_id);

    drprequestby.DataSource = dsdrop.Tables[0];

    drprequestby.DataTextField =
    "EmpName";drprequestby.DataValueField = "EmpID";

    drprequestby.DataBind();

    drprequestby.Items.Insert(0,
    new ListItem("All"));

     

     

    }

    else

    {

    for (int i = 0; i < drop_constsnt.Items.Count; i++)

    {

    if (drop_constsnt.Items[i].Value.Equals(Session["EmpID"].ToString()))

    {

    drop_constsnt.Items[i].Selected =
    true;

    Label2.Visible = true;

    DataSet dsdrop = new DataSet();dsdrop = objdept.GetRequesterName(Convert.ToInt64(drop_constsnt.SelectedValue.ToString()));

    drprequestby.DataSource = dsdrop.Tables[0];

    drprequestby.DataTextField = "EmpName";

    drprequestby.DataValueField = "EmpID";

    drprequestby.DataBind();

    drprequestby.Items.Insert(0,
    new ListItem("All"));

     

    }

    }

    }

     

    DateSelector1.CalendarDate =
    DateTime.Today.AddMonths(-1);DateSelector2.CalendarDate = DateTime.Today;

     

    //clsSqlDAL_TransferEmployee objstatus = new clsSqlDAL_TransferEmployee();

    DataTable dsall = new DataTable();

     

     

    DateTime ddd = DateSelector1.CalendarDate;

    DateTime eee = DateSelector1.CalendarDate;

    string abc = "";

    if (drop_constsnt.Visible == false)

    abc = Session["EmpID"].ToString();

    else

    abc = drop_constsnt.SelectedValue.ToString();

    string bbb = drpapprovests.SelectedValue.ToString();

    string ccc = drpIstrnsfrd.SelectedValue.ToString();

    if (ccc.Equals("null"))

    {

    bbb =
    "2";ccc = null;

    }

    objdept.ListRlvtTrnsfrReqs(
    Convert.ToInt64(Session["EmpID"].ToString()), Convert.ToInt64(abc), Convert.ToInt32(bbb), Convert.ToInt32(ccc), ddd, eee, ReqstrID);

    grdstatus.DataSource = dsall;

    grdstatus.DataBind();

     

     

    }

     

    }

    }

     

    problem is the data is not binding to gridview..

     

  • Re: Gridview. databind is not working..

    05-09-2008, 8:31 AM
    • Loading...
    • Curt_C
    • Joined on 07-23-2003, 8:27 PM
    • Stevens Point, WI - USA
    • Posts 3,653
    • Moderator
      TrustedFriends-MVPs

    wow... as a note, try to limit the code to the pertinate sections.

    Also, have you stepped through the code? Is there any data returned? Is one of the IF checks blocking your DataBind()? etc, etc...
    We need a little more to work on....

  • Re: Gridview. databind is not working..

    05-09-2008, 9:01 AM
    • Loading...
    • Raggers
    • Joined on 02-17-2006, 4:40 PM
    • Germany
    • Posts 81

    check two things

    1.datasource having data

    2.Autogenerate columns is set to true or false.By Default it should be true . 

    If this solves your problem please mark as answer
  • Re: Gridview. databind is not working..

    05-09-2008, 9:03 AM
    • Loading...
    • Mahadeomatre
    • Joined on 04-23-2007, 11:00 AM
    • Pune, India
    • Posts 190

    DataTable dsall = new DataTable();

    where u r filling this datatable in ur code?

    i thing ur datatable is blank and thats why ur grid is not showing anything.

    Thanks,
    Mahadeo

    -----------------------------------------------
    Best is Not the END point, but a starting point for Innovation
    ------------------------------------------------
    Remember to mark posts as the "Answer" to help future users.
  • Re: Gridview. databind is not working..

    05-09-2008, 9:27 AM

    new in .net...can u please tell how can i fiil data to this dataset..

Page 1 of 1 (5 items)