unbind a datagrid, datalist, repeater, drop down etc

Discussion in 'ASP .Net' started by Grant Merwitz, Jul 6, 2005.

  1. How do you unbind one of these web controls.

    I have a drop down list that based on another drop down list selection will
    be databouns

    private void BindDD2(int id)
    {
    DD2.DataSource = MyClass.GetList2(id);
    DD2.DataBind();
    }

    Now, if i want to reset this drop down back to its pre bound state, how
    would i do this.

    I've tried:

    1)
    DD2.DataSource = null; //didn't work
    2)
    foreach(ListItem l in DD2.Items)
    DD2.Items.Remoce(l); //also don't work
    3)
    DataSet ds = new DataSet();
    DD2.DataSource = ds;
    DD2.DataBind(); //this throws an error.


    So, any ideas

    TIA
     
    Grant Merwitz, Jul 6, 2005
    #1
    1. Advertising

  2. Hi!

    Try DD2.Items.Clear()

    HTH,
    Lars-Erik

    "Grant Merwitz" <> wrote in message
    news:OM3m%...
    > How do you unbind one of these web controls.
    >
    > I have a drop down list that based on another drop down list selection
    > will be databouns
    >
    > private void BindDD2(int id)
    > {
    > DD2.DataSource = MyClass.GetList2(id);
    > DD2.DataBind();
    > }
    >
    > Now, if i want to reset this drop down back to its pre bound state, how
    > would i do this.
    >
    > I've tried:
    >
    > 1)
    > DD2.DataSource = null; //didn't work
    > 2)
    > foreach(ListItem l in DD2.Items)
    > DD2.Items.Remoce(l); //also don't work
    > 3)
    > DataSet ds = new DataSet();
    > DD2.DataSource = ds;
    > DD2.DataBind(); //this throws an error.
    >
    >
    > So, any ideas
    >
    > TIA
    >
    >
     
    Lars-Erik Aabech, Jul 6, 2005
    #2
    1. Advertising

  3. knew it was something simple

    Thanks :)

    "Lars-Erik Aabech" <> wrote in message
    news:...
    > Hi!
    >
    > Try DD2.Items.Clear()
    >
    > HTH,
    > Lars-Erik
    >
    > "Grant Merwitz" <> wrote in message
    > news:OM3m%...
    >> How do you unbind one of these web controls.
    >>
    >> I have a drop down list that based on another drop down list selection
    >> will be databouns
    >>
    >> private void BindDD2(int id)
    >> {
    >> DD2.DataSource = MyClass.GetList2(id);
    >> DD2.DataBind();
    >> }
    >>
    >> Now, if i want to reset this drop down back to its pre bound state, how
    >> would i do this.
    >>
    >> I've tried:
    >>
    >> 1)
    >> DD2.DataSource = null; //didn't work
    >> 2)
    >> foreach(ListItem l in DD2.Items)
    >> DD2.Items.Remoce(l); //also don't work
    >> 3)
    >> DataSet ds = new DataSet();
    >> DD2.DataSource = ds;
    >> DD2.DataBind(); //this throws an error.
    >>
    >>
    >> So, any ideas
    >>
    >> TIA
    >>
    >>

    >
    >
     
    Grant Merwitz, Jul 6, 2005
    #3
  4. but how would this be done for a datagrid or datalist

    so DD2.Items.Clear() works perfectly on a dropdown
    but hows about a DataGrid?

    "Grant Merwitz" <> wrote in message
    news:OM3m%...
    > How do you unbind one of these web controls.
    >
    > I have a drop down list that based on another drop down list selection
    > will be databouns
    >
    > private void BindDD2(int id)
    > {
    > DD2.DataSource = MyClass.GetList2(id);
    > DD2.DataBind();
    > }
    >
    > Now, if i want to reset this drop down back to its pre bound state, how
    > would i do this.
    >
    > I've tried:
    >
    > 1)
    > DD2.DataSource = null; //didn't work
    > 2)
    > foreach(ListItem l in DD2.Items)
    > DD2.Items.Remoce(l); //also don't work
    > 3)
    > DataSet ds = new DataSet();
    > DD2.DataSource = ds;
    > DD2.DataBind(); //this throws an error.
    >
    >
    > So, any ideas
    >
    > TIA
    >
    >
     
    Grant Merwitz, Jul 6, 2005
    #4
  5. DD2.Items.Clear();

    Eliyahu

    "Grant Merwitz" <> wrote in message
    news:OM3m%...
    > How do you unbind one of these web controls.
    >
    > I have a drop down list that based on another drop down list selection

    will
    > be databouns
    >
    > private void BindDD2(int id)
    > {
    > DD2.DataSource = MyClass.GetList2(id);
    > DD2.DataBind();
    > }
    >
    > Now, if i want to reset this drop down back to its pre bound state, how
    > would i do this.
    >
    > I've tried:
    >
    > 1)
    > DD2.DataSource = null; //didn't work
    > 2)
    > foreach(ListItem l in DD2.Items)
    > DD2.Items.Remoce(l); //also don't work
    > 3)
    > DataSet ds = new DataSet();
    > DD2.DataSource = ds;
    > DD2.DataBind(); //this throws an error.
    >
    >
    > So, any ideas
    >
    > TIA
    >
    >
     
    Eliyahu Goldin, Jul 6, 2005
    #5
  6. Re: but how would this be done for a datagrid or datalist

    Depends if you want to keep the column headers. If not, you could just
    create an empty data source and bind. :)

    DataTable dt = new DataTable();
    // Create columns here..
    DataGrid1.DataSource = dt;
    DataGrid1.DataBind();

    Or you could set DataGrid1.EnableViewState = false, and repost the page..

    You could even do SELECT * FROM myTable WHERE myId = 0 and fill the data
    source, then you'd have the columns, but no data..

    The possibilities are many ;)

    Lars-Erik

    "Grant Merwitz" <> wrote in message
    news:%...
    > so DD2.Items.Clear() works perfectly on a dropdown
    > but hows about a DataGrid?
    >
    > "Grant Merwitz" <> wrote in message
    > news:OM3m%...
    >> How do you unbind one of these web controls.
    >>
    >> I have a drop down list that based on another drop down list selection
    >> will be databouns
    >>
    >> private void BindDD2(int id)
    >> {
    >> DD2.DataSource = MyClass.GetList2(id);
    >> DD2.DataBind();
    >> }
    >>
    >> Now, if i want to reset this drop down back to its pre bound state, how
    >> would i do this.
    >>
    >> I've tried:
    >>
    >> 1)
    >> DD2.DataSource = null; //didn't work
    >> 2)
    >> foreach(ListItem l in DD2.Items)
    >> DD2.Items.Remoce(l); //also don't work
    >> 3)
    >> DataSet ds = new DataSet();
    >> DD2.DataSource = ds;
    >> DD2.DataBind(); //this throws an error.
    >>
    >>
    >> So, any ideas
    >>
    >> TIA
    >>
    >>

    >
    >
     
    Lars-Erik Aabech, Jul 6, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SirPoonga
    Replies:
    2
    Views:
    799
    Ben Strackany
    Jan 7, 2005
  2. weiwei
    Replies:
    0
    Views:
    1,047
    weiwei
    Jan 5, 2007
  3. msimmons
    Replies:
    0
    Views:
    514
    msimmons
    Jul 16, 2009
  4. Replies:
    5
    Views:
    295
  5. Replies:
    3
    Views:
    312
Loading...

Share This Page