Click here to Skip to main content
15,886,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have designing in my web page
i have store the value in database ok but drop drown list value is not stored but i have select the first item. number 1 are stored ...and i have select the seventh item ...the number 7 are stored database The value not sored in a database how i change it
protected void btnSave_Click(object sender, EventArgs e)
       {

           Int32 st;
           int len = browseFilepath.PostedFile.ContentLength;
           byte[] pic = new byte[len];
           browseFilepath.PostedFile.InputStream.Read(pic, 0, len);

           SqlCommand Cmd = new SqlCommand();
           SqlConnection Cnn = new SqlConnection();
           string ConnectionString;
           ConnectionString = ConfigurationManager.ConnectionStrings["PhotostudioConnectionString"].ConnectionString;

           Cnn.ConnectionString = ConnectionString;
           if (Cnn.State != ConnectionState.Open)
               Cnn.Open();
           Cmd.Connection = Cnn;
           Cmd.CommandType = CommandType.StoredProcedure;
           Cmd.CommandText = "sproc_Ins_PhotoSettingsDetailses";
           Cmd.Parameters.Clear();
           // Cmd.Parameters.AddWithValue("@Id", txtBillNo.Text);
           Cmd.Parameters.AddWithValue("@Name", txtCName.Text);
           Cmd.Parameters.AddWithValue("@Phoneno", txtPhone.Text);
           Cmd.Parameters.AddWithValue("@Startdate", rdStartDate.SelectedDate);
           Cmd.Parameters.AddWithValue("@Enddate", rdEndDate.SelectedDate);
           Cmd.Parameters.Add("@Systemurl", SqlDbType.Image).Value = pic;
           SqlParameter Src = new SqlParameter("@FilePath", SqlDbType.NVarChar, 450);
           Src.Value = browseFilepath.PostedFile.FileName;
           Cmd.Parameters.Add(Src);
           Cmd.Parameters.AddWithValue("@Size", cmbSize.SelectedValue  );
           Cmd.Parameters.AddWithValue("@Amount",txtAmt.Text);
           Cmd.Parameters.AddWithValue("@Extracopies", txtNoofcopies.Text);
           Cmd.Parameters.AddWithValue("@Examount",TextBox1.Text );
           Cmd.Parameters.AddWithValue("@Lamination", Ddl.SelectedValue  );
           Cmd.Parameters.AddWithValue("@Laamount", txtlami.Text );
           Cmd.Parameters.AddWithValue("@Total", txtTot.Text );
           Cmd.Parameters.AddWithValue("@Grandtotal", txtgrandtot.Text );
           Cmd.Parameters.AddWithValue("@Paidamount", txtPaid.Text);
           Cmd.Parameters.AddWithValue("@Balance", txtbalance.Text );





           try
           {
               st = Convert.ToInt32(Cmd.ExecuteScalar());

           }
           catch (Exception ex)
           {
               throw new ApplicationException(
                   "!!! An Error Occured While getting Data From Hdr_AccountType." + ex.Message);
               lblError.Visible = true;
               lblError.Text = "!!! An Error Occured While " + ex.Message.ToString();
               return;
           }



           Cmd.Dispose();

My store procesure
SQL
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER PROCEDURE 
[dbo].[sproc_Ins_PhotoSettingsDetailses]
(
		  --@Id as Numeric(18,0),
          @Name	as  Varchar(100),
		  @Phoneno  as  Numeric(18,0),
		  @Startdate as datetime,
          @Enddate  as datetime,
		  @Systemurl as  Image,
		  @FilePath as NVarchar(450),
           @Size as nvarchar(50),
           @Amount as numeric(18,0),
           @Extracopies as numeric(18,0),
           @Examount as numeric (18,0),
           @Lamination as numeric(18,0),
           @Laamount as numeric(18,0),
           @Total as numeric(18,0),
           @Grandtotal as numeric (18,0),
		   @Paidamount as Numeric(18,0),
@Balance as numeric (18,0)
)     

AS
BEGIN

	
    INSERT INTO tblMainPhotosettings
           (	

Name,
				
Phoneno,
			
Startdate,
Enddate,
		
Systemurl,
		
FilePath,
 
Size,

Amount,
Extracopies,
Examount,
Lamination,
Laamount,
Total,
Grandtotal,
Paidamount,
Balance
)
     
          
     VALUES
           (
				
@Name,
				
@Phoneno,
@Startdate,
@Enddate,				
	
@Systemurl,
				
@FilePath,
@Size,
@Amount,
@Extracopies,
@Examount,
@Lamination,
@Laamount,
@Total,
@Grandtotal,
@Paidamount,
@Balance

)
Select @@Identity
END
Posted
Updated 26-May-11 23:04pm
v3
Comments
Deepthi Aravind 27-May-11 3:51am    
please clarify your question
Rob Branaghan 27-May-11 4:42am    
I believe what they are asking is
"Why doesnt the drop down list value save?"
Timberbird 27-May-11 4:51am    
Situation is still far from clear. Ok, let's see: you want to store multiple values gathered from your page in database. In your database you've created table to store data and stored procedure to write data in that table. You call sp from you code on button click. And everything is stored except one field - "Size", which should receive its value from combobox "cmbSize" via selected value. Right? If so, check whether you really assigned Value (not Text) to you combobox items. Remember, you are writing selected field value, not text or index in list!
kannan 2 27-May-11 5:00am    
ok

1 solution

With regards to your Drop Down List contents you wish to get, are they numbers such as

23,25,27

C#
protected void Page_Load(object sender, EventArgs e)
   {
       DropDownList1.Items.Add(new ListItem("23","23"));
       DropDownList1.Items.Add(new ListItem("25","25"));
       DropDownList1.Items.Add(new ListItem("27","27"));
   }
   protected void Button1_Click(object sender, EventArgs e)
   {
       if (DropDownList1.SelectedItem.Value != null)
       {
           string NeedToConvertThis = DropDownList1.SelectedItem.Value;
           int ConvertedInt = int.Parse(NeedToConvertThis);
           //Save ConvertedInt
       }
   }


Try doing something like this to get the value.
 
Share this answer
 
v2
Comments
Timberbird 27-May-11 5:00am    
I guess there are many choices. You can use SelectedValue, SelectedItem.Value (and i believe this is what should be used), SelectedItem.Text or SelectedIndex.ToString() depending on how your DropDownList declared and what do you store. Unfortunately, it isn't clear from the question. Oh, and one more general suggestion: null checks in case nothing is selected
kannan 2 27-May-11 5:02am    
The error display
Message 3 Validation (XHTML 1.0 Transitional): Attribute 'name' is considered outdated. A newer construct is recommended. D:\photostudiobackup\PhotoStudio\MasterPage.master 98 10 D:\photostudiobackup\PhotoStudio\
Message 4 Validation (XHTML 1.0 Transitional): Attribute 'border' is considered outdated. A newer construct is recommended. D:\photostudiobackup\PhotoStudio\MasterPage.master 98 74 D:\photostudiobackup\PhotoStudio\
Message 7 Validation (XHTML 1.0 Transitional): Attribute 'name' is considered outdated. A newer construct is recommended. D:\photostudiobackup\PhotoStudio\MasterPage.master 107 10 D:\photostudiobackup\PhotoStudio\
Message 8 Validation (XHTML 1.0 Transitional): Attribute 'border' is considered outdated. A newer construct is recommended. D:\photostudiobackup\PhotoStudio\MasterPage.master 107 74 D:\photostudiobackup\PhotoStudio\
Message 11 Validation (XHTML 1.0 Transitional): Attribute 'name' is considered outdated. A newer construct is recommended. D:\photostudiobackup\PhotoStudio\MasterPage.master 116 10 D:\photostudiobackup\PhotoStudio\
Message 12 Validation (XHTML 1.0 Transitional): Attribute 'border' is considered outdated. A newer construct is recommended. D:\photostudiobackup\PhotoStudio\MasterPage.master 116 74 D:\photostudiobackup\PhotoStudio\
Message 15 Validation (XHTML 1.0 Transitional): Attribute 'align' is considered outdated. A newer construct is recommended. D:\photostudiobackup\PhotoStudio\MainPage.aspx 20 25 D:\photostudiobackup\PhotoStudio\
Error 32 Non-invocable member 'System.Web.UI.WebControls.ListControl.SelectedItem' cannot be used like a method. D:\photostudiobackup\PhotoStudio\MainPage.aspx.cs 292 58
Timberbird 27-May-11 6:55am    
C'mon, compiler tells you everything. You write something like cmbSize.SelectedItem() while it has to be cmbSize.SelectedItem, without brackets

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