6
我創建了labels
和textboxes
動態。一切順利,但第二個label
不想出現。我錯在哪裏?這是我在C#中的代碼:我錯了?動態創建標籤c#
private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
OracleDataReader reader;
int x = 434;
int y = 84;
int i = 0;
try
{
conn.Open();
foreach (var itemChecked in checkedListBox1.CheckedItems)
{
Label NewLabel = new Label();
NewLabel.Location = new Point(x + 100, y);
NewLabel.Name = "Label" + i.ToString();
Controls.Add(NewLabel);
TextBox tb = new TextBox();
tb.Location = new Point(x, y);
tb.Name = "txtBox" + i.ToString();
Controls.Add(tb);
y += 30;
OracleCommand cmd = new OracleCommand("SELECT distinct data_type from all_arguments where owner='HR' and argument_name='" + itemChecked.ToString() + "'", conn);
reader = cmd.ExecuteReader();
while (reader.Read())
{
label[0].Text = reader["data_type"].ToString();
}
i++;
}
}
finally
{
if (conn != null)
conn.Close();
}
}
private void Procedure()
{
string proc = "";
try
{
conn.Open();
if (this.listView1.SelectedItems.Count > 0)
proc = listView1.SelectedItems[0].Text;
OracleCommand cmd = new OracleCommand("" + proc + "", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandTimeout = 600;
int i = 0;
foreach (var itemChecked1 in checkedListBox1.Items)
{
Control[] txt = Controls.Find("txtBox" + i.ToString(), false);
Control[] label = Controls.Find("Label" + i.ToString(), false);
cmd.Parameters.Add(new OracleParameter("select distinct data_type from all_arguments where owner='HR' and argument_name=toupper("+itemChecked1.ToString()+")",conn));
cmd.Parameters[":"+itemChecked1.ToString()+""].Value=label[0].Text;
cmd.Parameters.Add(new OracleParameter(":" + itemChecked1.ToString() + "", OracleDbType.Varchar2));
cmd.Parameters[":" + itemChecked1.ToString() + ""].Value = txt[0].Text;
i++;
查看html並驗證標籤是否存在。如果是,請使用瀏覽器的開發工具手動調整CSS。 IE9具有體面的內置工具,只需按F12即可。 – 2013-02-28 13:53:50
「我錯了?」除了SQL注入外,魔術變量名稱爲:int x = 434; int y = 84;',而且你正在爲每個* checked項目運行select語句?爲什麼你創建一個標籤只是爲了轉身找到它?直言不諱,我認爲你應該描述你正在嘗試做什麼,這樣我們可以拋出這些代碼並重新開始。 – aquinas 2013-02-28 14:06:42
我設法做到這一點,通過在這裏發佈的人,但我不知道他爲什麼刪除帖子。我將這兩行代碼中的標籤替換爲其他內容:Control [] label = Controls.Find(「Label」+ i.ToString(),false);和NewLabel.Name =「Label」+ i.ToString(); – Viva 2013-02-28 14:14:05