Add new item in Panel and save it for future

4 posts, 0 answers
  1. dotnetrockerzzz
    dotnetrockerzzz avatar
    32 posts
    Member since:
    Aug 2010

    Posted 12 Oct 2010 Link to this post

    I have following code :

    protected void Button1_Click(object sender, EventArgs e)
        {
            RadPanelItem newItem = new RadPanelItem(RadTextBox1.Text);
            RadPanelBar1.Items.Add(newItem);
             
        }
     Currently the scenario is ---
    User Clicks on button the item is added . When user refreshes the page the value is gone . 

    Wanted Scenario ----
    User Clicks on button the item is added . When user refreshes the page the value is still there

    I do not want any databases involved plz if possible . Thank You . Reply me fast plz 
  2. Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 12 Oct 2010 Link to this post

    Hello Vaibhav,

    You can use an XML file, instead of a database, to save the PanelBar structure. The following demo shows how to databind the PanelBar to an xml file.

    http://demos.telerik.com/aspnet-ajax/panelbar/examples/populatingwithdata/xmldefinition/defaultcs.aspx

    To save the PanelBar items, back to the xml file. You can the PanelBar.GetXml() method and then use a TextWriter to write the content to your xml file.

    I hope that helps.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. dotnetrockerzzz
    dotnetrockerzzz avatar
    32 posts
    Member since:
    Aug 2010

    Posted 13 Oct 2010 Link to this post

    @Cori
    "" use a TextWriter to write the content to your xml file."" Can u please explain me how ? Remember I want the value from a Textbox .  Thanks for the reply XML did not strike to me . Thanks .
    Vaibhav
  5. Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 13 Oct 2010 Link to this post

    You use the same code you posted in your first post, where you add it to the PanelBar. You then just create the TextWriter and pass it the content from GetXml. Something like this:

    RadPanelBarItem newItem = new RadPanelBarItem(RadTextBox1.Text);
    RadPanelBar1.Items.Add(newItem);
      
    StreamWriter sw = new StreamWriter("PanelBarItems.xml");
    sw.Write(RadPanelBar1.GetXml());
    sw.Flush();
    sw.Close();

    That should do the trick.

    I hope that helps.
Back to Top