Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hello Frnds !
 
am working on asp.net project using c# SqlServer 2005.
 
I have 10 Textboxes and a submit button on my webpage...this is use to save the data entered in database....its works fine.
 
My requirement is :
 
from total 10 textboxes i will enter only in 7 textboxes.... the first 3 textboxes will be as usual for every entry.
 
only once i will enter in first 3 texboxes...and nextTime i will enter in other 7 textboxes..i dont want to enter in first 3 tboxes.
 
the first 3 textboxes data will be common to all.
 
so please help me how to do this ?
 
Thanks
Posted 9-Apr-13 21:14pm
Comments
Software Engineer 892 at 10-Apr-13 2:43am
   
SORRY THIS IS MY CODE
 
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Web.Configuration;
 
public partial class _Default : System.Web.UI.Page
{
private static readonly string _connString = String.Empty;
SqlConnection con = new SqlConnection(_connString);
 

protected void Page_Load(object sender, EventArgs e)
{
 
}
protected void BtnSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(_connString);
con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select * from Equipment_Inventory", con);
SqlCommandBuilder builder = new SqlCommandBuilder(da);
DataSet ds = new DataSet("Equipment_Inventory");
da.Fill(ds, "Equipment_Inventory");
 
DataTable Equipment_InventoryTable = ds.Tables["Equipment_Inventory"];
DataRow row = Equipment_InventoryTable.NewRow();
 
row["Dept_code"] = TxtDeptCode.Text;
row["Dept_desc"] = TxtDescription.Text;
row["Dept_telno"] = TxtTelephoneNo.Text;
row["Dept_dirmgr"] = TxtDirector_Manager.Text;
row["Equipment_type"] = DDL_EquipmentType.SelectedItem.Text;
row["Maker"] = DDL_Maker.SelectedItem.Text;
row["Model"] = TxtModel.Text;
row["Serialno"] = TxtSerialNo.Text;
row["TagNo"] = TxtKKIA_GACA_tag.Text;
row["Assignedto"] = TxtAssignedTo.Text;
row["Location"] = TxtLocation.Text;
row["Dentry"] = DateTime.Now.ToString();
 
Equipment_InventoryTable.Rows.Add(row);
da.Update(ds, "Equipment_Inventory");
con.Close();
 
TxtDeptCode.Text = "";
TxtDescription.Text = "";
TxtTelephoneNo.Text = "";
TxtDirector_Manager.Text = "";
DDL_EquipmentType.SelectedItem.Text = "";
DDL_Maker.SelectedItem.Text = "";
TxtModel.Text = "";
TxtSerialNo.Text = "";
TxtKKIA_GACA_tag.Text = "";
TxtAssignedTo.Text = "";
TxtLocation.Text = "";

 

ScriptManager.RegisterStartupScript(this, this.GetType(), "RunCode", "javascript:alert('Inventory added Successfully');", true);
}
protected void BtnCancel_Click(object sender, EventArgs e)
{
TxtDeptCode.Text = "";
TxtDescription.Text = "";
TxtTelephoneNo.Text = "";
TxtDirector_Manager.Text = "";
DDL_EquipmentType.SelectedItem.Text = "";
DDL_Maker.SelectedItem.Text = "";

TxtModel.Text = "";
TxtSerialNo.Text = "";
TxtKKIA_GACA_tag.Text = "";
TxtAssignedTo.Text = "";
TxtLocation.Text = "";
}
 

static _Default()
{
_connString = WebConfigurationManager.ConnectionStrings["Inventory_DBConnectionString"].ConnectionString;
}
}
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

In your page load event, set the value of the textboxes whenever it's a postback - so the first time they will be empty and subsequently you set the values to whatever was submitted previously
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I am assuming that first 3 textboxes will have common or default values. If that is the case, why do you even need those 3 textboxes in the webpage?
 
Keep only 7 textboxes, enter the data you want. While submitting include first 3 default values and values entered in next 7 textboxes, then save them into database.
  Permalink  
Comments
Software Engineer 892 at 10-Apr-13 2:43am
   
SORRY THIS IS MY CODE
 
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Web.Configuration;
 
public partial class _Default : System.Web.UI.Page
{
private static readonly string _connString = String.Empty;
SqlConnection con = new SqlConnection(_connString);
 

protected void Page_Load(object sender, EventArgs e)
{
 
}
protected void BtnSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(_connString);
con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select * from Equipment_Inventory", con);
SqlCommandBuilder builder = new SqlCommandBuilder(da);
DataSet ds = new DataSet("Equipment_Inventory");
da.Fill(ds, "Equipment_Inventory");
 
DataTable Equipment_InventoryTable = ds.Tables["Equipment_Inventory"];
DataRow row = Equipment_InventoryTable.NewRow();
 
row["Dept_code"] = TxtDeptCode.Text;
row["Dept_desc"] = TxtDescription.Text;
row["Dept_telno"] = TxtTelephoneNo.Text;
row["Dept_dirmgr"] = TxtDirector_Manager.Text;
row["Equipment_type"] = DDL_EquipmentType.SelectedItem.Text;
row["Maker"] = DDL_Maker.SelectedItem.Text;
row["Model"] = TxtModel.Text;
row["Serialno"] = TxtSerialNo.Text;
row["TagNo"] = TxtKKIA_GACA_tag.Text;
row["Assignedto"] = TxtAssignedTo.Text;
row["Location"] = TxtLocation.Text;
row["Dentry"] = DateTime.Now.ToString();
 
Equipment_InventoryTable.Rows.Add(row);
da.Update(ds, "Equipment_Inventory");
con.Close();
 
TxtDeptCode.Text = "";
TxtDescription.Text = "";
TxtTelephoneNo.Text = "";
TxtDirector_Manager.Text = "";
DDL_EquipmentType.SelectedItem.Text = "";
DDL_Maker.SelectedItem.Text = "";
TxtModel.Text = "";
TxtSerialNo.Text = "";
TxtKKIA_GACA_tag.Text = "";
TxtAssignedTo.Text = "";
TxtLocation.Text = "";

 

ScriptManager.RegisterStartupScript(this, this.GetType(), "RunCode", "javascript:alert('Inventory added Successfully');", true);
}
protected void BtnCancel_Click(object sender, EventArgs e)
{
TxtDeptCode.Text = "";
TxtDescription.Text = "";
TxtTelephoneNo.Text = "";
TxtDirector_Manager.Text = "";
DDL_EquipmentType.SelectedItem.Text = "";
DDL_Maker.SelectedItem.Text = "";

TxtModel.Text = "";
TxtSerialNo.Text = "";
TxtKKIA_GACA_tag.Text = "";
TxtAssignedTo.Text = "";
TxtLocation.Text = "";
}
 

static _Default()
{
_connString = WebConfigurationManager.ConnectionStrings["Inventory_DBConnectionString"].ConnectionString;
}
}
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

this is just how you manage it or how you want it.I am give code example of vb.net
Protected Sub btnSendMail_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSendMail.ServerClick
'before inserting to database save in viewstate as follows
        ViewState("txt1") = txtCcMail.Text
'put your code to insert into database
''''''''''''''''
'once you inserted to database assign viewstate value back to respected textbox and clear other textboxes
        txttoMail.Text = ViewState("txt1")
    End Sub
Happy coding
  Permalink  
Comments
Software Engineer 892 at 10-Apr-13 2:39am
   
This is my code, Please help
 
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Web.Configuration;
 
public partial class ViewInventory : System.Web.UI.Page
{
private static readonly string _connString = String.Empty;
SqlConnection con = new SqlConnection(_connString);
 
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadInventoryData();
}
}
 

private void LoadInventoryData()
{
SqlConnection con = new SqlConnection(_connString);
 

//SqlCommand cmd = new SqlCommand("Select * from Equipment_Inventory", con);
SqlCommand cmd = new SqlCommand("Select Dept_code as DeptCode, Dept_desc as Description, Dept_telno as TelephoneNo, Dept_dirmgr as DirectorManager, Equipment_type as EquipmentType, Maker as Maker, Model as Model, Serialno as SerialNo, TagNo as TagNo, Assignedto as AssignedTo, Location as Location from Equipment_Inventory", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GVInventoryRecords.DataSource = ds;
GVInventoryRecords.DataBind();

 
}
 

static ViewInventory()
{
_connString = WebConfigurationManager.ConnectionStrings["Inventory_DBConnectionString"].ConnectionString;
}
}
Software Engineer 892 at 10-Apr-13 2:43am
   
SORRY THIS IS MY CODE
 
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Web.Configuration;
 
public partial class _Default : System.Web.UI.Page
{
private static readonly string _connString = String.Empty;
SqlConnection con = new SqlConnection(_connString);
 

protected void Page_Load(object sender, EventArgs e)
{
 
}
protected void BtnSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(_connString);
con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select * from Equipment_Inventory", con);
SqlCommandBuilder builder = new SqlCommandBuilder(da);
DataSet ds = new DataSet("Equipment_Inventory");
da.Fill(ds, "Equipment_Inventory");
 
DataTable Equipment_InventoryTable = ds.Tables["Equipment_Inventory"];
DataRow row = Equipment_InventoryTable.NewRow();
 
row["Dept_code"] = TxtDeptCode.Text;
row["Dept_desc"] = TxtDescription.Text;
row["Dept_telno"] = TxtTelephoneNo.Text;
row["Dept_dirmgr"] = TxtDirector_Manager.Text;
row["Equipment_type"] = DDL_EquipmentType.SelectedItem.Text;
row["Maker"] = DDL_Maker.SelectedItem.Text;
row["Model"] = TxtModel.Text;
row["Serialno"] = TxtSerialNo.Text;
row["TagNo"] = TxtKKIA_GACA_tag.Text;
row["Assignedto"] = TxtAssignedTo.Text;
row["Location"] = TxtLocation.Text;
row["Dentry"] = DateTime.Now.ToString();
 
Equipment_InventoryTable.Rows.Add(row);
da.Update(ds, "Equipment_Inventory");
con.Close();
 
TxtDeptCode.Text = "";
TxtDescription.Text = "";
TxtTelephoneNo.Text = "";
TxtDirector_Manager.Text = "";
DDL_EquipmentType.SelectedItem.Text = "";
DDL_Maker.SelectedItem.Text = "";
TxtModel.Text = "";
TxtSerialNo.Text = "";
TxtKKIA_GACA_tag.Text = "";
TxtAssignedTo.Text = "";
TxtLocation.Text = "";

 

ScriptManager.RegisterStartupScript(this, this.GetType(), "RunCode", "javascript:alert('Inventory added Successfully');", true);
}
protected void BtnCancel_Click(object sender, EventArgs e)
{
TxtDeptCode.Text = "";
TxtDescription.Text = "";
TxtTelephoneNo.Text = "";
TxtDirector_Manager.Text = "";
DDL_EquipmentType.SelectedItem.Text = "";
DDL_Maker.SelectedItem.Text = "";

TxtModel.Text = "";
TxtSerialNo.Text = "";
TxtKKIA_GACA_tag.Text = "";
TxtAssignedTo.Text = "";
TxtLocation.Text = "";
}
 

static _Default()
{
_connString = WebConfigurationManager.ConnectionStrings["Inventory_DBConnectionString"].ConnectionString;
}
}
kishore sharma at 10-Apr-13 2:43am
   
by looking at your code we can understand that here you are only displaying into grid,
where is submit part
Software Engineer 892 at 10-Apr-13 2:51am
   
i have send another code ..please help this is my code....THIS IS SUBMIT PART
 

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Web.Configuration;
 
public partial class _Default : System.Web.UI.Page
{
private static readonly string _connString = String.Empty;
SqlConnection con = new SqlConnection(_connString);
 

protected void Page_Load(object sender, EventArgs e)
{
 
}
protected void BtnSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(_connString);
con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select * from Equipment_Inventory", con);
SqlCommandBuilder builder = new SqlCommandBuilder(da);
DataSet ds = new DataSet("Equipment_Inventory");
da.Fill(ds, "Equipment_Inventory");
 
DataTable Equipment_InventoryTable = ds.Tables["Equipment_Inventory"];
DataRow row = Equipment_InventoryTable.NewRow();
 
row["Dept_code"] = TxtDeptCode.Text;
row["Dept_desc"] = TxtDescription.Text;
row["Dept_telno"] = TxtTelephoneNo.Text;
row["Dept_dirmgr"] = TxtDirector_Manager.Text;
row["Equipment_type"] = DDL_EquipmentType.SelectedItem.Text;
row["Maker"] = DDL_Maker.SelectedItem.Text;
row["Model"] = TxtModel.Text;
row["Serialno"] = TxtSerialNo.Text;
row["TagNo"] = TxtKKIA_GACA_tag.Text;
row["Assignedto"] = TxtAssignedTo.Text;
row["Location"] = TxtLocation.Text;
row["Dentry"] = DateTime.Now.ToString();
 
Equipment_InventoryTable.Rows.Add(row);
da.Update(ds, "Equipment_Inventory");
con.Close();
 
TxtDeptCode.Text = "";
TxtDescription.Text = "";
TxtTelephoneNo.Text = "";
TxtDirector_Manager.Text = "";
DDL_EquipmentType.SelectedItem.Text = "";
DDL_Maker.SelectedItem.Text = "";
TxtModel.Text = "";
TxtSerialNo.Text = "";
TxtKKIA_GACA_tag.Text = "";
TxtAssignedTo.Text = "";
TxtLocation.Text = "";

 

ScriptManager.RegisterStartupScript(this, this.GetType(), "RunCode", "javascript:alert('Inventory added Successfully');", true);
}
 

protected void BtnCancel_Click(object sender, EventArgs e)
{
TxtDeptCode.Text = "";
TxtDescription.Text = "";
TxtTelephoneNo.Text = "";
TxtDirector_Manager.Text = "";
DDL_EquipmentType.SelectedItem.Text = "";
DDL_Maker.SelectedItem.Text = "";

TxtModel.Text = "";
TxtSerialNo.Text = "";
TxtKKIA_GACA_tag.Text = "";
TxtAssignedTo.Text = "";
TxtLocation.Text = "";
}
 

static _Default()
{
_connString = WebConfigurationManager.ConnectionStrings["Inventory_DBConnectionString"].ConnectionString;
}
}
kishore sharma at 10-Apr-13 3:00am
   
among these textbox which you want to keep as it is
just remove those textbox from this list in your code (submit part)it should be fine.
TxtDeptCode.Text = "";
TxtDescription.Text = "";
TxtTelephoneNo.Text = "";
TxtDirector_Manager.Text = "";
DDL_EquipmentType.SelectedItem.Text = "";
DDL_Maker.SelectedItem.Text = "";
TxtModel.Text = "";
TxtSerialNo.Text = "";
TxtKKIA_GACA_tag.Text = "";
TxtAssignedTo.Text = "";
TxtLocation.Text = "";
Software Engineer 892 at 10-Apr-13 3:00am
   
remove first 3 textboxes
kishore sharma at 10-Apr-13 3:03am
   
yes and check
Software Engineer 892 at 10-Apr-13 3:04am
   
Hello boss if i remove that 3 textboxes code...am unable to see the entered values in database from that textboxes..
Software Engineer 892 at 10-Apr-13 3:09am
   
My requirement is :
 
Total i have 10 textboxes and a submit button. this data will be save in database...its fine till here.
 
Now my requirement is ?
 
for first record i will enter all the textboxes and clicks on submit button..its saves in DB.
 
for second record only i will enter other 7 textboxes...because the first 3 boxes will be common to all records.
 
so that, if i enter in 7 textboxes....in database i should see complete 10 textboxes data in one record.
 
please help.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Check with some this i have done small changes ,just storing values in viewstae and rebinding to textbox
 
protected void BtnSubmit_Click(object sender, EventArgs e) 
{
 SqlConnection con = new SqlConnection(_connString); con.Open(); SqlDataAdapter da = new SqlDataAdapter("Select * from Equipment_Inventory", con); 
SqlCommandBuilder builder = new SqlCommandBuilder(da); DataSet ds = new DataSet("Equipment_Inventory"); da.Fill(ds, "Equipment_Inventory");
 DataTable Equipment_InventoryTable = ds.Tables["Equipment_Inventory"]; DataRow row = Equipment_InventoryTable.NewRow();
 row["Dept_code"] = TxtDeptCode.Text;
 row["Dept_desc"] = TxtDescription.Text; 
row["Dept_telno"] = TxtTelephoneNo.Text; 
Viewstate("Dept_code")= TxtDeptCode.Text;
Viewstate("Dept_telno")= TxtTelephoneNo.Text; 
Viewstate("Dept_desc") = TxtDescription.Text; 
row["Dept_dirmgr"] = TxtDirector_Manager.Text;
 row["Equipment_type"] = DDL_EquipmentType.SelectedItem.Text; 
row["Maker"] = DDL_Maker.SelectedItem.Text;
 row["Model"] = TxtModel.Text;
 row["Serialno"] = TxtSerialNo.Text; 
row["TagNo"] = TxtKKIA_GACA_tag.Text;
 row["Assignedto"] = TxtAssignedTo.Text; 
row["Location"] = TxtLocation.Text; 
row["Dentry"] = DateTime.Now.ToString();
 Equipment_InventoryTable.Rows.Add(row); 
da.Update(ds, "Equipment_Inventory"); 
con.Close(); 
 TxtDeptCode.Text=Viewstate("Dept_code");
 TxtTelephoneNo.Text=Viewstate("Dept_telno");
TxtDescription.Text=Viewstate("Dept_desc") ;
 TxtDirector_Manager.Text = ""; 
DDL_EquipmentType.SelectedItem.Text = "";
 DDL_Maker.SelectedItem.Text = ""; 
TxtModel.Text = "";
 TxtSerialNo.Text = "";
 TxtKKIA_GACA_tag.Text = "";
 TxtAssignedTo.Text = ""; 
TxtLocation.Text = ""; 
ScriptManager.RegisterStartupScript(this, this.GetType(), "RunCode", "javascript:alert('Inventory added Successfully');", true);
 
 } 
  Permalink  
Comments
Software Engineer 892 at 10-Apr-13 3:47am
   
I have pasted ur code....but it shows an error
 
The name 'ViewState' does not exist in the current context

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

  Print Answers RSS
0 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 479
2 Maciej Los 305
3 Mathew Soji 195
4 Afzaal Ahmad Zeeshan 170
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,777
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 10 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100