Showing posts with label Hide row in Detailsview. Show all posts
Showing posts with label Hide row in Detailsview. Show all posts

December 14, 2011

Details View Row Invisible from Code Behind

Below is the sample code if you want to make some rows invisible in details view

//Method to Bind details View from DB

 public void GetUserProfile()
    {
        DataSet ds = sqlobj.RunQueryReturnDataSetonLoginDB("exec [GetServiceUsage] '" + Session["UserId"].ToString() + "'" + "," + 0);
        if (ds != null)
        {
            if (ds.Tables[0] != null) 
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    dView.DataSource = ds.Tables[0];
                    dView.DataBind();


                }


            }


        }




    }


//Make Specific rows which have cell text ="0" invisible

    if (dView != null)
            {
                DataRowView row = dView.DataItem as DataRowView;
                
                    if (row  != null)
                    {
                       //Row 1
                        if (row["Testrow"].ToString() == "0" )
                        {
                            dView.Rows[0].Visible = false;


                        }


                      //Row 2
                        if (row["Testrow2"].ToString() == "0" )
                        {
                            dView.Rows[1].Visible = false;


                        }


                    }
                
            }