Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Comments
Software Engineer 892 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;
}
}

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
 
Share this answer
 
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.
 
Share this answer
 
Comments
Software Engineer 892 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;
}
}
this is just how you manage it or how you want it.I am give code example of vb.net
VB
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
 
Share this answer
 
Comments
Software Engineer 892 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 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 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 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 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 = "";
Check with some this i have done small changes ,just storing values in viewstae and rebinding to textbox
C#
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);

 } 
 
Share this answer
 
Comments
Software Engineer 892 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)



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