Hello,
I have sql table which stores controlnames and control types
controltype controlname
TextBox txt1
TextBox txt2
I want to give controlids dynamically from controlname but I am getting stuck when I am looping through controls,please advice.here is code
private void dditem_SelectedIndexChanged(object sender, System.EventArgs e)
{
SqlConnection dataConn= new SqlConnection();
dataConn.ConnectionString="xxxxx";
dataConn.Open();
SqlCommand deviceCmd = new SqlCommand("p_NADA_GetControls",dataConn);
deviceCmd.CommandType=CommandType.StoredProcedure;
SqlParameter deviceParm = deviceCmd.Parameters.Add("@Device", SqlDbType.NVarChar, 25);
deviceParm.Value = "Computer";
SqlCommand TxtCountCmd = new SqlCommand("p_NADA_GetTextCount",dataConn);
TxtCountCmd.CommandType=CommandType.StoredProcedure;
SqlParameter TxtCountParm = TxtCountCmd.Parameters.Add("@Device", SqlDbType.NVarChar, 25);
TxtCountParm.Value = "Computer";
SqlDataReader TxtCountReader = TxtCountCmd.ExecuteReader();
while (TxtCountReader.Read())
{
tcount=(int)TxtCountReader["ct"];
}
TxtCountReader.Close();
SqlDataReader DeviceReader = deviceCmd.ExecuteReader();
while (DeviceReader.Read())
{
string ctype = (string)DeviceReader["ControlType"];
phControl.Visible=true;
phControl.Controls.Add(new LiteralControl("<table>"));
if (ctype=="TextBox")
{
for (int i = 0; i < tcount; i++)
{
TextBox txtTextBox= new TextBox();
txtTextBox.ID = (string)DeviceReader["ControlName"];
phControl.Visible=true;
//phControl.Controls.Add(new LiteralControl("<tr>"));
phControl.Controls.Add(new LiteralControl("<td class='TextBox'>"));
phControl.Controls.Add(txtTextBox);
}
}
}
DeviceReader.Close();
dataConn.Close();
I have sql table which stores controlnames and control types
controltype controlname
TextBox txt1
TextBox txt2
I want to give controlids dynamically from controlname but I am getting stuck when I am looping through controls,please advice.here is code
private void dditem_SelectedIndexChanged(object sender, System.EventArgs e)
{
SqlConnection dataConn= new SqlConnection();
dataConn.ConnectionString="xxxxx";
dataConn.Open();
SqlCommand deviceCmd = new SqlCommand("p_NADA_GetControls",dataConn);
deviceCmd.CommandType=CommandType.StoredProcedure;
SqlParameter deviceParm = deviceCmd.Parameters.Add("@Device", SqlDbType.NVarChar, 25);
deviceParm.Value = "Computer";
SqlCommand TxtCountCmd = new SqlCommand("p_NADA_GetTextCount",dataConn);
TxtCountCmd.CommandType=CommandType.StoredProcedure;
SqlParameter TxtCountParm = TxtCountCmd.Parameters.Add("@Device", SqlDbType.NVarChar, 25);
TxtCountParm.Value = "Computer";
SqlDataReader TxtCountReader = TxtCountCmd.ExecuteReader();
while (TxtCountReader.Read())
{
tcount=(int)TxtCountReader["ct"];
}
TxtCountReader.Close();
SqlDataReader DeviceReader = deviceCmd.ExecuteReader();
while (DeviceReader.Read())
{
string ctype = (string)DeviceReader["ControlType"];
phControl.Visible=true;
phControl.Controls.Add(new LiteralControl("<table>"));
if (ctype=="TextBox")
{
for (int i = 0; i < tcount; i++)
{
TextBox txtTextBox= new TextBox();
txtTextBox.ID = (string)DeviceReader["ControlName"];
phControl.Visible=true;
//phControl.Controls.Add(new LiteralControl("<tr>"));
phControl.Controls.Add(new LiteralControl("<td class='TextBox'>"));
phControl.Controls.Add(txtTextBox);
}
}
}
DeviceReader.Close();
dataConn.Close();