Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
The task is that I need to add values in the textbox and as I click on the additem button the value will be added to the radlistbox and to display the added values in the another page. As I add values and then click on the save button only the last value that I given as Input is been displayed and other values are not been displayed. Can anyone help me to sole this problem.

HTML
NewsTicker.NewsItemsCsv = repository.Rows[0]["NewsTickerItems"].ToString();
string[] split = this.uxNewTicker.Text.Split(',');
            foreach (var s in split)
            {
                ShowRepositoryFields();
                uxTickerItems.Items.Add(new RadListBoxItem(s));
            }


The above code is to display the values in another page.

ASP.NET
 <asp:Label ID="Label1" runat="server" AssociatedControlID="uxNewTicker">Enable Ticker</asp:Label>
<asp:CheckBox runat="server" id="tickerCheck"/><br />
<div id="tickerdisplay">
<asp:Label ID="Label2" runat="server" >News Items</asp:Label>
<asp:TextBox runat="server" ID="uxNewTicker" placeholder="Enter news item text" maxlength="150"></asp:TextBox>
<input type="submit" name="addItem" value="Add New Item" /><br />
<telerik:RadListBox  runat="server" ID="uxTickerItems" Width="500px" Height="200px" 
AllowReorder="true" AllowDelete="true" ShowCheckAll="True" PersistClientChanges="true" />


The above code is the aspx code to display.

HTML
internal bool Save(ePIMS.Collaboration.Documents.Bll.Repository RepositoryObject, int DocumentRepositoryID, int ApplicationID, string RepositoryName, string Title, string BodyText,string NewsTickerItems, string Identifier )
       {
           return base.Save(RepositoryObject, "Save", "usp_DocumentRepositorySave",
               new SqlParameter("@DocumentRepositoryID", DocumentRepositoryID),
               new SqlParameter("@ApplicationID", ApplicationID),
               new SqlParameter("@RepositoryName", RepositoryName),
               new SqlParameter("@Title", Title),
               new SqlParameter("@BodyText", BodyText),
               new SqlParameter("@NewsTickerItems", NewsTickerItems),
               new SqlParameter("@Identifier", Identifier)
               );

       }


The above code is the SQL queries to add data to the database.
Posted
Updated 17-Mar-15 1:08am
Comments
Sinisa Hajnal 17-Mar-15 7:30am    
Set a breakpoint in save and check that each time you click addItem your item gets saved. Then check how many rows there are in your repository because you're just getting first one.

1 solution

for example:
OdbcConnection connection = new OdbcConnection(MyConnectionString);
OdbcCommand queryCmd;
C#
queryCmd = connection.CreateCommand();
              queryCmd.CommandText = "Insert Into cli_detail(cli_Name,cli_Addr,cli_City,cli_State,cli_Country,Phonenumber,Comments,Gender,Dob,Age,Hobbies)values(?,?,?,?,?,?,?,?,?,?,?)";
              queryCmd.Parameters.AddWithValue("@Cli_Name", txtName.Text);
              queryCmd.Parameters.AddWithValue("@Cli_Addr", txtAddress.Text);
              queryCmd.Parameters.AddWithValue("@Cli_City", txtCity.Text);
              queryCmd.Parameters.AddWithValue("@Cli_State", txtState.Text);
              queryCmd.Parameters.AddWithValue("@Cli_Country", txtCountry.Text);
              queryCmd.Parameters.AddWithValue("@Phonenumber",Int32.Parse(txtPhonenumber.Text));
              queryCmd.Parameters.AddWithValue("@Comments", txtComments.Text);
              if (rdoFemale.Checked)
              {
                  queryCmd.Parameters.AddWithValue("@Gender :" , rdoFemale.Text);
              }
              else
              {
                  queryCmd.Parameters.AddWithValue("@Gender :" ,rdoMale.Text);
              }
              DateTime theDate = Convert.ToDateTime(dtpDob.Text)  ;

              queryCmd.Parameters.AddWithValue("@Dob" ,theDate.ToString("yyyy-MM-dd"));
              queryCmd.Parameters.AddWithValue("@Age" ,Int32.Parse(nuAge.Text));
              string hobies = "";
              foreach (string chk in lstHobbies.SelectedItems )
              {
                  hobies += "," + chk;
                                  }
              queryCmd.Parameters.AddWithValue("@Hobbies:", hobies);
             var x= queryCmd.ExecuteNonQuery();

          }
 catch (Exception)
            {
                throw;
            }

            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                    LoadData();
                }
            }
        }
 private void LoadData()
                {
                     OdbcConnection  connection=new OdbcConnection(MyConnectionString);
                     connection.Open();
                    try
                    {
                        OdbcCommand queryCmd = connection.CreateCommand();
                        queryCmd.CommandText="select * from table name";
                        OdbcDataAdapter adap = new OdbcDataAdapter(queryCmd);
                        DataSet ds = new DataSet();
                        adap.Fill(ds);
                       //                       DataGridView1.DataSource = ds.Tables[0].DefaultView;
                       
                    }
                    catch(Exception)
                    {
                        throw;
                    }
                    finally
                    {
                        if(connection.State==ConnectionState.Open)
                        {
                            connection.Close();
                        }
                     }
                }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900