我想在每次迭代时手动更改变量的值,但我不想更改渐变计算,有人可以告诉我该怎么做吗?
答案 0 :(得分:1)
private void loadCandidates()
{
try
{
sql = "exec dbo.spLoadCandidates @NationalID, @PostID";
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
SqlDataReader reader;
cmd.Parameters.AddWithValue("@NationalID", TextBox2.Text.Trim());
cmd.Parameters.AddWithValue("@PostID", DropDownList1.SelectedValue);
conn.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
Label myLabel = new Label();
ImageButton myImage = new ImageButton();
myImage.OnClientClick = "ImageClick1(this);";
UpdatePanel myPanel = new UpdatePanel();
RadioButton myRadioButton = new RadioButton();
candidates.Add(myRadioButton);
myImage.ImageUrl = "Handler4.ashx?ID=" + reader["IDNo"].ToString();
myRadioButton.GroupName = "Candidates";
myRadioButton.ID = reader["CID"].ToString();
myRadioButton.ClientIDMode = ClientIDMode.Static;
myPanel.Controls.Add(myPanel); //add the panel to the placeholder
myPanel.Controls.Add(myImage);
myPanel.Controls.Add(myLabel);
myPanel.Controls.Add(myRadioButton); //add the radiobutton to the panel
AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
trigger.EventName = "Click";
trigger.ControlID = myImage.UniqueID;
UpdatePanel1.Triggers.Add(trigger);
}
conn.Close();
}
}
catch (Exception ex)
{
Label1.Text = ex.Message;
Label1.Visible = true;
Label2.Visible = false;
}
finally
{
conn.Close();
}
}