Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 7th, 2006, 02:06 AM
Authorized User
 
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hide a Row in a FormView Control


On this form, all of the fields will go into one row in a table. However, depending on which product the user is ordering, not all of the fields are required. If a field is not required it will get a Null value.

I have the logic in the code behind to determine which fields should be visible.

I am currently using a formview control (that defaults to insert mode) to collect the information but am not having any luck hiding a row, I can't figure out how to reference it in the code behind.

Feel free to let me know if I am going about this entirely the wrong way too please.



 
Old July 7th, 2006, 10:50 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I don't see a way of eliminating a row from the formview. You will need to exclude the row(s) you want from the datasorce used for the formview.

 
Old July 13th, 2006, 04:48 PM
Authorized User
 
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am sorry, I misspoke on the first request, the form view is only in insert mode, so I don't need to exlude a ROW from the form, but specific COLUMNS based on values in another table.

Here is simplified example.

jobType Table has 2 columns, requiresName and requiresDate

the form in question, will be collecting data to go in the jobs table.
When the form is compiled, it will check the jobType tbl to see if the requiresName and requiresDate fields are checked. If they are, those fields should be visible in the form. If they are not checked, those two fields should not be visible on the form and they will be submitted into the jobs table with NULL values.

Here is what I have so far.

if (!Page.IsPostBack)
        {
            SqlConnection MyConnection;
            SqlCommand MyCommand;
            SqlDataReader MyReader;
            SqlParameter lobParam;

            MyConnection = new SqlConnection();
            MyConnection.ConnectionString = ConfigurationManager.ConnectionStrings["rdConnectionString"].ConnectionString;

            MyCommand = new SqlCommand();
            MyCommand.CommandText =
               " SELECT * FROM LinesOfBusiness WHERE lobID = @lobID ";
            MyCommand.CommandType = CommandType.Text;
            MyCommand.Connection = MyConnection;

            lobParam = new SqlParameter();
            lobParam.ParameterName = "@lobID";
            lobParam.SqlDbType = SqlDbType.Int;
            lobParam.Size = 4;
            lobParam.Direction = ParameterDirection.Input;
            lobParam.Value = "2";

            MyCommand.Parameters.Add(lobParam);

            MyCommand.Connection.Open();
            MyReader = MyCommand.ExecuteReader(CommandBehavior.CloseConne ction);





            if (MyReader.Read())
            {
                string codeStr = "";
                if (MyReader.GetBoolean(MyReader.GetOrdinal("requires PropAddress")) == true)

                    //code to set visiblility of form field, this is the part I can't get to work.

            }

            MyCommand.Dispose();
            MyConnection.Dispose();

        }
    }
 
Old July 13th, 2006, 10:59 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

FormView1.Row.Cells(0).FindControl("YourControl"). Visible = false;

 
Old July 14th, 2006, 02:27 PM
Authorized User
 
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, that worked.

 
Old July 14th, 2006, 03:07 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

glad to help :)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Row is null after formview insert?? stapes ASP.NET 2.0 Basics 1 June 27th, 2008 10:19 AM
FormView Control lokraj ASP.NET 2.0 Basics 0 September 11th, 2007 08:51 AM
show/hide row(s) eugz Beginning PHP 0 March 19th, 2006 10:10 PM
Hide Row with VBA Butch Excel VBA 2 November 24th, 2004 09:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.