.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old May 9th, 2008, 06:28 AM
hippie hippie is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 15 hippie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 2 m 12 sec
Reputation Power: 0
ASP.Net/C# - Grid_RowDataBound - SelectedIndexChanged

Hi...
Can some one please please explain this to me cause i am finding it really weird and i have been on it for ages...

i am creating a dynamic gridview at runtime. i have a dropdownlist in my gridview when i select an item from the dropdownlist the selectedindexchanged is not firing for each item in the dropdownlist.

since i am creating a dynamic gridview everytime the page is loaded or postback the dynamic gridview is being created. so the dropdownlist is being populated everytime but for some weird reason as i said above the selectedindexchange of the dropdownlist is not firing all the time.

i have set the autopostback and enableviewstate for all controls and pages to be true.. but still it is not solving the problem..

what i have noticed is that in order for the selectedindexchange to work on an item that didnt fire the selectedindexchange , i would run the app, select the item obviously the selectedindexchanged event will not fire then i close the app, then run it again, then when i select t item from the dropdownlist then it fires the selectedindexchanged event...

weird yeah.........

thanks in advance for anyhelp...

my code is below

Code:
 void ITemplate.InstantiateIn(System.Web.UI.Control container)
    {
        container.EnableViewState = true;
        switch (_templateType)
        {
            case ListItemType.Header:
                //Creates a new label control and add it to the container.
                Label lbl = new Label();            //Allocates the new label object.
                lbl.Text = _columnName;    //Assigns the name of the column in the lable.
                
                container.Controls.Add(lbl);//Adds the newly created label control to the container.

                break;

            case ListItemType.Item:
                //Creates a new text box control and add it to the container.

                if (_columnName == "ID")
                {
                    Label lblID = new Label();//Allocates the new text box object.
                    lblID.DataBinding += new EventHandler(lblID_DataBinding);//Attaches the data binding event
                    lblID.Width = ((Unit)200);
                    lblID.Visible = true;
                    container.Controls.Add(lblID);
                    break;
                }
                else if (_columnName == "Guid")
                {
                    Label lblGUID = new Label();
                    lblGUID.DataBinding += new EventHandler(lblGUID_DataBinding);
                    lblGUID.Width = ((Unit)200);
                    lblGUID.Visible = true;
                    container.Controls.Add(lblGUID);
                }
                else if (_columnName == "Fields")
                {
                    DropDownList ddlFields = new DropDownList();
                    ddlFields.DataBinding += new EventHandler(ddlFields_DataBinding);
                    ddlFields.Width = ((Unit)200);
                    container.Controls.Add(ddlFields);
                }
                else if (_columnName == "OperatorType")
                {
                    DropDownList ddlOperator = new DropDownList();
                    ddlOperator.DataBinding += new EventHandler(ddlOperator_DataBinding);
                    ddlOperator.Width = ((Unit)200);
                    container.Controls.Add(ddlOperator);

                }
                else if (_columnName == "EnterValue")
                {
                    TextBox txtEnterValue = new TextBox();
                    txtEnterValue.DataBinding += new EventHandler(txtEnterValue_DataBinding);
                    txtEnterValue.Width = ((Unit)100);
                    container.Controls.Add(txtEnterValue);
                }
                else if (_columnName == "Add")
                {
                    Button btnAdd = new Button();
                    btnAdd.Text = "Add";
                    btnAdd.DataBinding += new EventHandler(btnAdd_DataBinding);
                    btnAdd.Width = 50; ;
                    container.Controls.Add(btnAdd);
                }
                else if (_columnName == "Remove")
                {
                    Button btnRemove = new Button();
                    btnRemove.Text = "Remove";
                    btnRemove.DataBinding += new EventHandler(btnRemove_DataBinding);
                    btnRemove.Width = 50;
                    container.Controls.Add(btnRemove);
                }

                break;
        }
    }

   

    void txtEnterValue_DataBinding(object sender, EventArgs e)
    {
        //throw new Exception("The method or operation is not implemented.");
        TextBox txtEnterValue = (TextBox)sender;
        txtEnterValue.ID = "txtEnterValue";
        GridViewRow container = (GridViewRow)txtEnterValue.NamingContainer;

        object dataValue = DataBinder.Eval(container.DataItem, _columnName);

        if (dataValue != null)
        {
            txtEnterValue.Text = dataValue.ToString();
        }  
    }

    void ddlOperator_DataBinding(object sender, EventArgs e)
    {
        //throw new Exception("The method or operation is not implemented.");
        DropDownList ddlOperator = (DropDownList)sender;
        ddlOperator.ID = "ddlOperator";
        //ddlOperator.EnableViewState = true;
        //ddlOperator.AutoPostBack = true;
        GridViewRow container = (GridViewRow)ddlOperator.NamingContainer;
            object dataValue  = DataBinder.Eval(container.DataItem, _columnName);

            if (dataValue != null)
            {
                ddlOperator.DataSource = dataValue;
                ddlOperator.DataValueField = "ID";
                ddlOperator.DataTextField = "Description";
            }

    }

    void ddlFields_DataBinding(object sender, EventArgs e)
    {
        //throw new Exception("The method or operation is not implemented.");

        DropDownList ddlFields = (DropDownList)sender;
        ddlFields.ID = "ddlFields";
        ddlFields.SelectedIndexChanged += new EventHandler(ddlFields_SelectedIndexChanged);
       
        ddlFields.EnableViewState = true;
        ddlFields.AutoPostBack = true;
        
        GridViewRow container = (GridViewRow)ddlFields.NamingContainer;
        object dataValue = DataBinder.Eval(container.DataItem, _columnName);

        if (dataValue != null)
        {
            ddlFields.DataSource = dataValue;
            ddlFields.DataValueField = "SuperType";
            ddlFields.DataTextField = "FieldName";
        }
    }

    void ddlFields_SelectedIndexChanged(object sender, EventArgs e)
    {
        //throw new NotImplementedException();


    }

  
    void lblGUID_DataBinding(object sender, EventArgs e)
    {
        //throw new Exception("The method or operation is not implemented.");

        Label lblGUID = (Label)sender;
        lblGUID.ID = "GUID";
        lblGUID.Visible = true;
        GridViewRow container = (GridViewRow)lblGUID.NamingContainer;

        object dataValue = DataBinder.Eval(container.DataItem, _columnName);

        if (dataValue != DBNull.Value)
        {
            lblGUID.Text = dataValue.ToString();
        }
    }

    void lblID_DataBinding(object sender, EventArgs e)
    {
        //throw new Exception("The method or operation is not implemented.");
        Label lblID = (Label)sender;
        lblID.ID = "ID";
        lblID.Visible = true;
        GridViewRow container = (GridViewRow)lblID.NamingContainer;

        object dataValue = DataBinder.Eval(container.DataItem, _columnName);

        if (dataValue != DBNull.Value)
        {
            lblID.Text = dataValue.ToString();
        }
    }

    void btnAdd_DataBinding(object sender, EventArgs e)
    {
        //throw new Exception("The method or operation is not implemented.");
        Button btnAdd = (Button)sender;
        GridViewRow container = (GridViewRow)btnAdd.NamingContainer;

        btnAdd.ID = "btnAdd";
        btnAdd.CommandName = "Add";
        btnAdd.CommandArgument = container.DataItemIndex.ToString();
        object dataValue = DataBinder.Eval(container.DataItem, _columnName);

        if (dataValue != DBNull.Value)
        {
            btnAdd.Text = dataValue.ToString();
        }
    }

    void btnRemove_DataBinding(object sender, EventArgs e)
    {
        //throw new Exception("The method or operation is not implemented.");
        Button btnRemove = (Button)sender;
        GridViewRow container = (GridViewRow)btnRemove.NamingContainer;

        btnRemove.ID = "btnRemove";
        btnRemove.CommandName = "Remove";
        btnRemove.CommandArgument = container.DataItemIndex.ToString();

        object dataValue = DataBinder.Eval(container.DataItem, _columnName);

        if (dataValue != null)
        {
            btnRemove.Text = dataValue.ToString();
        }

        if (container.DataItemIndex > 0)
        {
            btnRemove.Enabled = true;
        }
        else
        {
            btnRemove.Enabled = false;
        
        }

    }

Reply With Quote
  #2  
Old May 12th, 2008, 03:13 AM
hippie hippie is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 15 hippie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 2 m 12 sec
Reputation Power: 0
help

anyone out there .. that knows the answer to this...

thanks in advance...

Reply With Quote
Reply

Viewing: ASP Free ForumsProgramming.NET Development > ASP.Net/C# - Grid_RowDataBound - SelectedIndexChanged


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway