plz help me to use a textbox control id as costume variable deifine in

hi i am add some textbox in a table at run time. i define the id of textbox using loop variable i: like (tb.ID = texbox + i.ToString();. that is ok but i want to use that id in my sql query but the no of textbox is define by user so i don't now how many they are so i try to use them as variable id like ( textbox + i.ToString()+.Text) in my query but it is not working. value pass to the query is ("textbox1.Text' or "textbox2.Text") but origanal value is not pass. plZ help me out


my code
protected void LinkButton1_Click(object sender, EventArgs e)
{
int i = new int();
int j = new int();
for (i =1; i <= int.Parse(tbequipno.Text); i++)
{
TableRow row = new TableRow();
for (j = 1; j <= 4; j++)
{
TableCell cell = new TableCell();
cell.Width = 150;
TextBox tb = new TextBox();
tb.ID = "tbrowcol" + i.ToString() + j.ToString();
tb.Width = 116;
cell.Controls.Add(tb);
row.Cells.Add(cell);
}
Table1.Rows.Add(row);
}


}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
SqlConnection conn = Connection.GetConnection();

SqlCommand cmd = new SqlCommand("INSERT INTO [NetworkAssetDetail] ([Building_Code], [BuildingName], [Floor], [Rack], [LocationInBuilding], [KeyNo], [KeyAvailability], [IPPhoneNo]) VALUES ('"+ ddlbuildtype.SelectedValue +"','"+ ddlbuildname.SelectedItem + "','" + ddlfloor.SelectedValue +"','"+ ddlrack.SelectedValue +"','"+ tblocation.Text +"','"+ tbkeyno.Text + "','" + tbkeyavai.Text +"','"+ tbipphone.Text + "')", conn);
// try
{
cmd.ExecuteNonQuery();
int tempsno = new int();
conn.Close();
SqlConnection conn2 = Connection.GetConnection();
SqlCommand cmd3 = new SqlCommand("SELECT sno from NetworkAssetDetail WHERE Building_Code ='" + ddlbuildtype.SelectedValue + "' AND BuildingName ='" + ddlbuildname.SelectedItem +"' AND Floor ='"+ ddlfloor.SelectedValue + "' AND Rack ='" +ddlrack.SelectedValue + "'",conn2);
SqlDataReader dtr = cmd3.ExecuteReader();

Response.Write(cmd3.CommandText);
if (dtr.HasRows == true)
{
// Response.Write(dtr["sno"].ToString());
// tempsno = int.Parse(dtr["sno"].ToString());
}
dtr.Close();
int i = new int();
for (i = 1; i <= int.Parse(tbequipno.Text); i++)
{
SqlCommand cmd2 = new SqlCommand("INSERT INTO [NetworkEquipmentDetail] ([sno], [Type], [Detail], [SerialNO], [IOSVersion]) VALUES (" + tempsno + ",'" + ("tbrowcol" + i.ToString() + "1.Text") + "','" + ("tbrowcol" + i.ToString() + "2.Text") + "','" + ("tbrowcol" + i.ToString() + "3.Text") + "','" + ("tbrowcol" + i.ToString() + "4.Text") + "')", conn2);
cmd2.ExecuteNonQuery();
}

MsgBox1.alert("Detail Saved: ");
tbipphone.Text = "";
tbequipno.Text = "";
tbkeyavai.Text = "";
tbkeyno.Text = "";
tblocation.Text = "";
ddlbuildname.SelectedIndex = 0;
ddlbuildtype.SelectedIndex = 0;
ddlfloor.SelectedIndex = 0;
ddlrack.SelectedIndex = 0;


conn2.Close();

}

// catch
{

MsgBox1.alert("Some invalid detail ");

}



}

Comments

  • you can set the textbox controls property 'autopostback' as true
    and get the value entered in each text when the postback is done
    did u also try to use repeaters and placeholders ?it may solve ur problem
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion