将一个文本框值放入另一个 [英] putting one textbox value into another
问题描述
public partial class Master:System.Web.UI.MasterPage
{
protected void Page_Load(object sender,EventArgs e)
{
string strConnString = ConfigurationManager.ConnectionStrings [amitpandeyConnectionString]。ConnectionString;
string str;
SqlCommand com;
lb1.Text = +WELLCOME ::++ + Session [ UserName] +;
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str =select * from Login where UserName ='+ Session [UserName] +';
com = new SqlCommand(str,con);
SqlDataAdapter da = new SqlDataAdapter(com);
DataSet ds = new DataSet();
da.Fill(ds);
lbl_address.Text = ds.Tables [0] .Rows [0] [UserId]。ToString();
lbl_sal.Text = ds.Tables [0] .Rows [0] [Branch]。ToString();
lbl_phone.Text = ds.Tables [0] .Rows [0] [指定] .ToString();
}
protected void btnSubmit_Click(object sender,EventArgs e)
{
int [] nos = new int [Convert.ToInt32(txtNo.Text)];
for(int i = 0;我< nos.Length; i ++)
nos [i] = i + 1;
GridView1.DataSource = nos;
GridView1.DataBind();
}
protected void btnInsert_Click(object sender,EventArgs e)
{
foreach(GridView1.Rows中的GridViewRow gvRow)
{
TextBox txtBranch =(TextBox)gvRow.FindControl(txtBranch);
TextBox txtDate =(TextBox)gvRow.FindControl( txtDate);
TextBox txtSrNo =(TextBox)gvRow.FindControl(txtSrNo);
TextBox txtDocketNo =(TextBox)gvRow.FindControl(txtDocketNo) ;
TextBox txtPinCode =(TextBox)gvRow.FindControl(txtPinCode);
TextBox txtBasis =(TextBox)gvRow.FindControl(txtBasis);
TextBox txtTo =(TextBox)gvRow.FindControl(txtTo);
TextBox txtConsignorCode =(TextBox)gvRow.FindControl(txtConsignor);
TextBox txtConsignee =(TextBox)gvRow.FindControl(txtConsignee);
TextBox txtPKTS =(TextBox)gvRow.FindControl(txtPKTS);
TextBox txtActWt =(TextBox)gvRow.FindControl(txtActWt);
TextBox txtChargeWt =(TextBox)gvRow.FindControl(txtChargeWt);
TextBox txtTotalFreight = (TextBox)gvRow.FindControl(txtTotalFreight);
TextBox txtGoodsType =(TextBox)gvRow.FindControl(txtGoodsType);
TextBox txtCODamount =(TextBox)gvRow .FindControl(txtCODamount);
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings [amitpandeyConnectionString]。ConnectionString);
SqlCommand cmd = new SqlCommand(插入CreateDocket值(@ Branch,@ Date,@ SrNo,@ DocketNo,@ PinCode,@ Basis,@ To,@ ConsignorCode,@ Consignee,@ PKTS,@ ActWt,@ ChargeWt,@ TotalFreight ,@ GoodsType,CODamount),c on);
cmd.Parameters.Clear();
cmd.Parameters.Add(Branch,txtBranch.Text);
cmd.Parameters.Add(Date,txtDate.Text);
cmd.Parameters.Add(SrNo,txtSrNo);
cmd.Parameters.Add( DocketNo,txtDocketNo.Text);
cmd.Parameters.Add(PinCode,txtPinCode.Text);
cmd.Parameters.Add(Basis, txtBasis.Text);
cmd.Parameters.Add(To,txtTo.Text);
cmd.Parameters.Add(ConsignorCode,txtConsignorCode.Text) ;
cmd.Parameters.Add(收货人,txtConsignee.Text);
cmd.Parameters.Add(PKTS,txtPKTS.Text);
cmd.Parameters.Add(ActWt,txtActWt.Text);
cmd.Parameters.Add(ChargeWt,txtChargeWt.Text);
cmd.Parameters.Add(TotalFreight,txtTotalFreight.Text);
cmd.Parameters。添加(GoodsType,txtGoodsType.Text);
cmd.Parameters.Add(CODamount,txtCODamount.Text);
cmd.ExecuteNonQuery();
con.Close();
}
}
}
我想要什么是lbl_sal.Text显示哪个分支是logedin,我希望当页面加载时,分支的所有文本框中都会出现相同的文本
< blockquote>尝试
foreach(GridView1.Rows中的GridViewRow gvRow)
{
gvRow.FindControl(txtBranch)= lbl_sal.Text;
}
public partial class Master : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
string strConnString = ConfigurationManager.ConnectionStrings["amitpandeyConnectionString"].ConnectionString;
string str;
SqlCommand com;
lb1.Text = "" + "WELLCOME:: " + "" + "" + Session["UserName"] + "";
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from Login where UserName='" + Session["UserName"] + "'";
com = new SqlCommand(str, con);
SqlDataAdapter da = new SqlDataAdapter(com);
DataSet ds = new DataSet();
da.Fill(ds);
lbl_address.Text = ds.Tables[0].Rows[0]["UserId"].ToString();
lbl_sal.Text = ds.Tables[0].Rows[0]["Branch"].ToString();
lbl_phone.Text = ds.Tables[0].Rows[0]["Designation"].ToString();
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
int[] nos = new int[Convert.ToInt32(txtNo.Text)];
for (int i = 0; i < nos.Length; i++)
nos[i] = i + 1;
GridView1.DataSource = nos;
GridView1.DataBind();
}
protected void btnInsert_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvRow in GridView1.Rows)
{
TextBox txtBranch = (TextBox)gvRow.FindControl("txtBranch");
TextBox txtDate = (TextBox)gvRow.FindControl("txtDate");
TextBox txtSrNo = (TextBox)gvRow.FindControl("txtSrNo");
TextBox txtDocketNo = (TextBox)gvRow.FindControl("txtDocketNo");
TextBox txtPinCode = (TextBox)gvRow.FindControl("txtPinCode");
TextBox txtBasis = (TextBox)gvRow.FindControl("txtBasis");
TextBox txtTo = (TextBox)gvRow.FindControl("txtTo");
TextBox txtConsignorCode = (TextBox)gvRow.FindControl("txtConsignor");
TextBox txtConsignee = (TextBox)gvRow.FindControl("txtConsignee");
TextBox txtPKTS = (TextBox)gvRow.FindControl("txtPKTS");
TextBox txtActWt = (TextBox)gvRow.FindControl("txtActWt");
TextBox txtChargeWt = (TextBox)gvRow.FindControl("txtChargeWt");
TextBox txtTotalFreight = (TextBox)gvRow.FindControl("txtTotalFreight");
TextBox txtGoodsType = (TextBox)gvRow.FindControl("txtGoodsType");
TextBox txtCODamount = (TextBox)gvRow.FindControl("txtCODamount");
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["amitpandeyConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("insert into CreateDocket values (@Branch,@Date,@SrNo,@DocketNo,@PinCode,@Basis,@To,@ConsignorCode,@Consignee,@PKTS,@ActWt,@ChargeWt,@TotalFreight,@GoodsType,CODamount)", con);
cmd.Parameters.Clear();
cmd.Parameters.Add("Branch", txtBranch.Text);
cmd.Parameters.Add("Date", txtDate.Text);
cmd.Parameters.Add("SrNo", txtSrNo);
cmd.Parameters.Add("DocketNo", txtDocketNo.Text);
cmd.Parameters.Add("PinCode", txtPinCode.Text);
cmd.Parameters.Add("Basis", txtBasis.Text);
cmd.Parameters.Add("To", txtTo.Text);
cmd.Parameters.Add("ConsignorCode", txtConsignorCode.Text);
cmd.Parameters.Add("Consignee", txtConsignee.Text);
cmd.Parameters.Add("PKTS", txtPKTS.Text);
cmd.Parameters.Add("ActWt", txtActWt.Text);
cmd.Parameters.Add("ChargeWt", txtChargeWt.Text);
cmd.Parameters.Add("TotalFreight", txtTotalFreight.Text);
cmd.Parameters.Add("GoodsType", txtGoodsType.Text);
cmd.Parameters.Add("CODamount", txtCODamount.Text);
cmd.ExecuteNonQuery();
con.Close();
}
}
}
What I want is lbl_sal.Text shows me which branch is logedin, I wanted that same text may come in all the textbox of branch when page loads
Tryforeach (GridViewRow gvRow in GridView1.Rows) { gvRow.FindControl("txtBranch") = lbl_sal.Text; }
这篇关于将一个文本框值放入另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!