Click here to Skip to main content
15,902,939 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Calling __doPostBack() Pin
ToddHileHoffer5-Feb-09 2:29
ToddHileHoffer5-Feb-09 2:29 
QuestionHow to Transfer Data From SQL Server 2000 to MS Access using c# Pin
Vishal094-Feb-09 1:57
Vishal094-Feb-09 1:57 
AnswerRe: How to Transfer Data From SQL Server 2000 to MS Access using c# Pin
Manas Bhardwaj4-Feb-09 2:34
professionalManas Bhardwaj4-Feb-09 2:34 
AnswerRe: How to Transfer Data From SQL Server 2000 to MS Access using c# Pin
Paddy Boyd4-Feb-09 3:00
Paddy Boyd4-Feb-09 3:00 
JokeRe: How to Transfer Data From SQL Server 2000 to MS Access using c# Pin
ToddHileHoffer4-Feb-09 8:27
ToddHileHoffer4-Feb-09 8:27 
QuestionControls not visible Pin
sana174-Feb-09 1:56
sana174-Feb-09 1:56 
AnswerRe: Controls not visible Pin
Christian Graus4-Feb-09 9:23
protectorChristian Graus4-Feb-09 9:23 
Question[newbie] Dropdownlist control disappearing Pin
jon-804-Feb-09 1:52
professionaljon-804-Feb-09 1:52 
I'm having an unusual problem where a control of type System.Web.UI.WebControls.Dropdownlist is somehow disappearing when I select 'Save' on my form. I've gone through my code a couple of times and I'm not explicitly altering its Visible property.

Control ProductVersion is disappearing when I select 'Save'. In the code this is captured within protected void btnMultifunction_Click(object sender, EventArgs e)

Confused | :confused:

Here's the code ...

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;
using System.Data.SqlClient;
using System.IO;

public partial class TaskEntry : System.Web.UI.Page
{
    //TODO: Update _DBConnString to read from web.config.
    private const string _DBConnString = "Data Source=JCAMILLERI\\SQLEXPRESS;Initial Catalog=teamwiki;User ID=teamwiki;Password=password;";
    private SqlConnection _conAppDB = new SqlConnection(_DBConnString);
    private enum multifunctionButtonFunction {Create, Update, NoUpdate}
    private int _selectedProduct = 0;

    protected void Page_Load(object sender, EventArgs e)
    {  
        //Binding Product 
        try
           
        {   
            //required because Autopostback is true.
            if (!IsPostBack) { 
                _conAppDB.Open();

                //populate Product     
                Product.Items.Clear();

                SqlCommand _getProductSQL = new SqlCommand
                    (@"select [productID_PK], [product] + ' (' + [product_shortname] + ')' as product
                from [teamwiki].[dbo].[product_L]
                where [in_use] = 1
                order by [product] ASC", _conAppDB);

                SqlDataReader _ProductNames = _getProductSQL.ExecuteReader();
                Product.DataSource = _ProductNames;
                Product.DataTextField = "product";
                Product.DataValueField = "productID_PK";
                Product.DataBind();

                _ProductNames.Close();

         }

        }
        catch (Exception ex) { 
            throw ex; }
        finally {
            if (_conAppDB.State == ConnectionState.Open)
            { _conAppDB.Close(); }
            
        }

  
    }

    protected void btnMultifunction_Click(object sender, EventArgs e)
    {
        multifunctionButtonFunction ButtonMode = multifunctionButtonFunction.Create;

        if (btnMultifunction.Text == "Create new task")
            //TODO: Use enums instead of text for validating btnMultifunction
        {
            Product.Enabled = true;
            calIdealDeliveryDate.Enabled = true;
            calLatestDeliveryDate.Enabled = true;
            txtRequestedBy.Enabled = true;
            lstTaskSubCategory.Enabled = true;
            txtTaskDescription.Enabled = true;
            lstPriority.Enabled = true;

            btnMultifunction.Text = "Save";
            ButtonMode = multifunctionButtonFunction.Update;
        }
        else if (btnMultifunction.Text == "Save") { 
            /* TODO: Insert new task in database and generate task_ref (last 6 digits)
                    show it in bold and ask user to take note of this reference.
             */
            Product.Enabled = false;
            ProductVersion.Visible = true; //TEMP
            ProductVersion.Enabled = false;
            calIdealDeliveryDate.Enabled = false;
            calLatestDeliveryDate.Enabled = false;
            txtRequestedBy.Enabled = false;
            lstTaskSubCategory.Enabled = false;
            txtTaskDescription.Enabled = false;
            lstPriority.Enabled = false;

            //Validation 1: Dates cannot be in the past.
            if (calIdealDeliveryDate.SelectedDate < DateTime.Now && ButtonMode == multifunctionButtonFunction.Update)
            {
                Response.Write("Dates cannot be in the past");
                ButtonMode = multifunctionButtonFunction.NoUpdate;
           
            }

            if (calLatestDeliveryDate.SelectedDate < DateTime.Now)
            {
                Response.Write("Date cannot be in the past");
                ButtonMode = multifunctionButtonFunction.NoUpdate;
                
            }

            //Insert to database and display task reference
            if (ButtonMode != multifunctionButtonFunction.NoUpdate) {
            try
            {
                _conAppDB.Open();
                
                string _createNewTaskQuery = (@"INSERT INTO [teamwiki].[dbo].[task]
                                        ([category_FK1]
                                       ,[sub_category_FK2]
                                       ,[task_description]
                                       ,[priority_FK3]
                                       ,[status_FK4]
                                       ,[start_date]
                                       ,[ideal_delivery_date]
                                       ,[latest_delivery_date]
                                       ,[task_deadline]
                                       ,[request_date]
                                       ,[requesting_user]
                                       ,[assigned_to]
                                       ,[managed_by]
                                       ,[implementor_notes]
                                       ,[attachment] 
                                       ,[last_update]
                                       ,[in_use]
                                       ,[productID_FK5]
                                       ,[product_release_FK6])
            VALUES                    ( @category, 
                                       @sub_category,
                                       @task_description,
                                       @priority,
                                       @status, 
                                       NULL,
                                       @ideal_delivery_date,
                                       @latest_delivery_date,
                                       NULL,
                                       GETDATE(),
                                       @requesting_user,
                                       NULL,
                                       NULL,
                                       NULL,
                                       NULL,
                                       GETDATE(),
                                       @in_use,
                                       @product,
                                       @product_release)");
                SqlCommand cmdCreateNewTaskQuery = new SqlCommand(_createNewTaskQuery, _conAppDB);
                                                            
                cmdCreateNewTaskQuery.Parameters.AddWithValue("@category", Global.TaskCategory);   /*TODO: Currently hard-coded.  Should map to Global.TaskCategory i.e. the option
                                                                                                        that the user selected in Welcome.aspx. */
                 
                cmdCreateNewTaskQuery.Parameters.AddWithValue("@sub_category", lstTaskSubCategory.SelectedValue); 
                      
                cmdCreateNewTaskQuery.Parameters.AddWithValue("@task_description", txtTaskDescription.Text);

                //Int32.TryParse(lstPriority.SelectedValue.ToString(), out _priority);
                cmdCreateNewTaskQuery.Parameters.AddWithValue("@priority", 1); //TODO:  Currently hard-coded; to retrieve selection from lstPriority.
                
                cmdCreateNewTaskQuery.Parameters.AddWithValue("@status", 1); //1 - not started [dbo.task_status_L]              
                cmdCreateNewTaskQuery.Parameters.AddWithValue("@ideal_delivery_date", calIdealDeliveryDate.SelectedDate);
                cmdCreateNewTaskQuery.Parameters.AddWithValue("@latest_delivery_date", calLatestDeliveryDate.SelectedDate);
                cmdCreateNewTaskQuery.Parameters.AddWithValue("@requesting_user", txtRequestedBy.Text);
                cmdCreateNewTaskQuery.Parameters.AddWithValue("@in_use", 1); //Bit data type: 1 – true; 0 – false.

                //int _selectedProduct = int.Parse(Products.SelectedDataKey.Value.ToString());
                cmdCreateNewTaskQuery.Parameters.AddWithValue("@product", 1); //TODO: Update to read values selected by user
                cmdCreateNewTaskQuery.Parameters.AddWithValue("@product_release", 1); //TODO: Update to read values selected by user
                //cmdCreateNewTaskQuery.Parameters.AddWithValue("@product", _selectedProduct); 
                

                cmdCreateNewTaskQuery.ExecuteNonQuery();

                //retrieve greatest taskRef to txtTaskRef
                string getTaskRef = @"SELECT MAX([taskID_PK]) FROM [teamwiki].[dbo].[task];";
                SqlCommand getTaskRefSQL = new SqlCommand(getTaskRef, _conAppDB);
                object taskRef = getTaskRefSQL.ExecuteScalar();
                if (taskRef != DBNull.Value)
                {
                    txtTaskRef.Text = taskRef.ToString();
                }
                
                btnMultifunction.Enabled = false;
                
            }
            catch (InvalidCastException)
            { 
                //Occurs when database is empty.
            }
            catch (Exception ex)
            {
                throw ex;
                
            }
            finally {
                _conAppDB.Close();
            }      
        } 
    } 
    }

    protected void lstPriority_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void txtIdealDeliveryDate_TextChanged(object sender, EventArgs e)
    {
        
    }
    protected void calLatestDeliveryDate_SelectionChanged(object sender, EventArgs e)
    {

    }
    
    protected void Products_SelectedIndexChanged(object sender, EventArgs e)
    {
        //Assumption: When this is databound, a value has to be selected by the user
        //TODO:  Within error trapping test this assumption.

       if (ProductVersion.Visible == false){ 
            ProductVersion.Visible = true;
            ProductVersion.Enabled = true;
       
            //read Product selected by the user
            string _selectedProduct_s = Product.SelectedValue.ToString();

            if (int.TryParse(_selectedProduct_s, out _selectedProduct) == false)
            {
                //TODO: Error handling
                throw new Exception();
            }
           
            //populate ProductVersion
           try
            {              
     
                _conAppDB.Open();

                //Binding ProductVersion to read items
                ProductVersion.Items.Clear();
                SqlCommand _getProductVersionSQL = new SqlCommand
                    (@"select product_releaseID_PK, version
                from [teamwiki].[dbo].[product_release]
                where [in_use] = 1
                and productID_FK2 = @productID;", _conAppDB);

                _getProductVersionSQL.Parameters.AddWithValue("@productID", _selectedProduct);

                SqlDataReader _ProductVersion = _getProductVersionSQL.ExecuteReader();
                
                ProductVersion.DataSource = _ProductVersion;
                ProductVersion.DataTextField = "version";
                ProductVersion.DataValueField = "product_releaseID_PK";
                ProductVersion.DataBind();
                
               _ProductVersion.Close();
                    
            }
            catch (Exception ex) {
                throw ex;
            }
            finally {
                
                _conAppDB.Close();
            } 
            
        } 
                        
        }

    protected void ProductVersion_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}


Jon

AnswerRe: [newbie] Dropdownlist control disappearing Pin
Vimalsoft(Pty) Ltd4-Feb-09 2:32
professionalVimalsoft(Pty) Ltd4-Feb-09 2:32 
GeneralRe: [newbie] Dropdownlist control disappearing Pin
jon-804-Feb-09 2:52
professionaljon-804-Feb-09 2:52 
GeneralRe: [newbie] Dropdownlist control disappearing Pin
Not Active4-Feb-09 10:30
mentorNot Active4-Feb-09 10:30 
QuestionSerialize, then directly in DB Pin
mehrdadc484-Feb-09 1:40
mehrdadc484-Feb-09 1:40 
AnswerRe: Serialize, then directly in DB Pin
Fayu4-Feb-09 10:05
Fayu4-Feb-09 10:05 
QuestionGridView Pin
GomathiR4-Feb-09 1:38
GomathiR4-Feb-09 1:38 
AnswerRe: GridView Pin
sarang_k4-Feb-09 5:06
sarang_k4-Feb-09 5:06 
GeneralRe: GridView Pin
GomathiR4-Feb-09 17:26
GomathiR4-Feb-09 17:26 
GeneralRe: GridView Pin
Jeneesh K. Velayudhan11-Jan-10 17:28
Jeneesh K. Velayudhan11-Jan-10 17:28 
QuestionAccess ASP.NET application in LAN Pin
avvaru.murali4-Feb-09 0:17
avvaru.murali4-Feb-09 0:17 
AnswerRe: Access ASP.NET application in LAN Pin
SeMartens4-Feb-09 0:34
SeMartens4-Feb-09 0:34 
QuestionWebUIValidation.js and .NET 2.0 upgrade [modified] Pin
imnotso#4-Feb-09 0:10
imnotso#4-Feb-09 0:10 
AnswerRe: WebUIValidation.js and .NET 2.0 upgrade Pin
Not Active4-Feb-09 1:18
mentorNot Active4-Feb-09 1:18 
QuestionAsp.net Gridview Header Pin
SreejithKumar M4-Feb-09 0:06
SreejithKumar M4-Feb-09 0:06 
QuestionHow convert string to xml Pin
Guvera3-Feb-09 23:41
Guvera3-Feb-09 23:41 
AnswerRe: How convert string to xml Pin
Manas Bhardwaj4-Feb-09 1:17
professionalManas Bhardwaj4-Feb-09 1:17 
AnswerRe: How convert string to xml Pin
SeMartens4-Feb-09 1:27
SeMartens4-Feb-09 1:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.