スコアリング シート アプリを開発しています。ラジオ ボタン付きのリピーターがあります。ラジオをチェックすると、ポップアップが表示されます。それは正常に動作します。しかし、問題は、別の行の次のラジオをチェックするたびに、ポップアップが重複して表示されることです (1 つは新しいラジオ用で、もう 1 つは以前にチェックしたラジオ用です)。これは、リピーターのすべての行で発生します (20 個のラジオをチェックした場合) 20 行で同時に 20 個のポップアップが表示されます) ラジオは常にチェックされている必要がありますが、Autopost は毎回それらの背後にあるコードを起動するためです。
コードはリピーターの PreRender イベントの下にありましたが、誰かがリピーターから取り出すことを提案しました。(ちなみに、PreRender イベントと ItemDataBound イベントの違いは何ですか?) 助けてください。
これは私のコードです:
namespace GAPP
{
public partial class GRADE : System.Web.UI.Page
{
bool rdchk = false;
protected void Page_Load(object sender, EventArgs e)
{
//-----------to define an event handler for the RadioButton control inside a repeater----------
this.rptr1.ItemDataBound += new RepeaterItemEventHandler(rptr1_ItemDataBound);
if (IsPostBack)
{
for (int i = 0; i < this.rptr1.Items.Count; i++)
{
RadioButton RDB1 = rptr1.Items[i].FindControl("L1") as RadioButton;
RadioButton RDB2 = rptr1.Items[i].FindControl("L2") as RadioButton;
RadioButton RDB3 = rptr1.Items[i].FindControl("L3") as RadioButton;
RadioButton RDB4 = rptr1.Items[i].FindControl("L4") as RadioButton;
RadioButton RDB5 = rptr1.Items[i].FindControl("R1") as RadioButton;
RadioButton RDB6 = rptr1.Items[i].FindControl("R2") as RadioButton;
RadioButton RDB7 = rptr1.Items[i].FindControl("R3") as RadioButton;
RadioButton RDB8 = rptr1.Items[i].FindControl("R4") as RadioButton;
RDB1.AutoPostBack = true;
RDB1.CheckedChanged += new EventHandler(RDBX1_CheckedChanged);
RDB2.AutoPostBack = true;
RDB2.CheckedChanged += new EventHandler(RDBX2_CheckedChanged);
RDB3.AutoPostBack = false;
RDB3.CheckedChanged += new EventHandler(RDBX2_CheckedChanged);
RDB4.AutoPostBack = true;
RDB4.CheckedChanged += new EventHandler(RDBX2_CheckedChanged);
RDB5.AutoPostBack = true;
RDB5.CheckedChanged += new EventHandler(RDBX1_CheckedChanged);
RDB6.AutoPostBack = true;
RDB6.CheckedChanged += new EventHandler(RDBX2_CheckedChanged);
RDB7.AutoPostBack = false;
RDB7.CheckedChanged += new EventHandler(RDBX2_CheckedChanged);
RDB8.AutoPostBack = true;
RDB8.CheckedChanged += new EventHandler(RDBX2_CheckedChanged);
}
}
}
//----------------------------end of define event-----------------------------------------
private void RDBX1_CheckedChanged(Object sender, EventArgs e)
{
foreach (RepeaterItem item in rptr1.Items)
{
if (item.ItemType == ListItemType.AlternatingItem || item.ItemType == ListItemType.Item)
{
AjaxControlToolkit.ModalPopupExtender mpex1 = (AjaxControlToolkit.ModalPopupExtender)item.FindControl("ModalPopupExtender1");
AjaxControlToolkit.ModalPopupExtender mpex2 = (AjaxControlToolkit.ModalPopupExtender)item.FindControl("ModalPopupExtender2");
Button bsr1 = (Button)item.FindControl("btn_saveRep1");
Button bsr2 = (Button)item.FindControl("btn_saveRep2");
Button bsr3 = (Button)item.FindControl("btn_repeat_cnxl1");
Button bsr4 = (Button)item.FindControl("btn_repeat_cnxl2");
RadioButton l1 = (RadioButton)item.FindControl("L1");
RadioButton r1 = (RadioButton)item.FindControl("R1");
if (l1.Checked && rdchk == false)
{
bsr1.Visible = true;
bsr2.Visible = false;
bsr3.Visible = true;
bsr4.Visible = false;
mpex2.Show();
}
if (r1.Checked && rdchk == false)
{
bsr1.Visible = false;
bsr2.Visible = true;
bsr3.Visible = false;
bsr4.Visible = true;
mpex2.Show();
}
}
}
}
private void RDBX2_CheckedChanged(Object sender, EventArgs e)
{
foreach (RepeaterItem item in rptr1.Items)
{
if (item.ItemType == ListItemType.AlternatingItem || item.ItemType == ListItemType.Item)
{
AjaxControlToolkit.ModalPopupExtender mpex1 = (AjaxControlToolkit.ModalPopupExtender)item.FindControl("ModalPopupExtender1");
AjaxControlToolkit.ModalPopupExtender mpex2 = (AjaxControlToolkit.ModalPopupExtender)item.FindControl("ModalPopupExtender2");
RadioButton l2 = (RadioButton)item.FindControl("L2");
if (l2.Checked) mpex1.Show();
RadioButton l4 = (RadioButton)item.FindControl("L4");
if (l4.Checked) mpex1.Show();
RadioButton r2 = (RadioButton)item.FindControl("R2");
if (r2.Checked) mpex1.Show();
RadioButton r4 = (RadioButton)item.FindControl("R4");
if (r4.Checked) mpex1.Show();
}
}
}
protected void rptr1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
}
protected void rptr1_PreRender(object sender, EventArgs e)
{
foreach (RepeaterItem item in rptr1.Items)
{
if (item.ItemType == ListItemType.AlternatingItem || item.ItemType == ListItemType.Item)
{
CheckBox chb = (CheckBox)item.FindControl("chkb_NO");
Label lbl1 = (Label)item.FindControl("lbl_dg_task");
Label lbl2 = (Label)item.FindControl("lbl_dg_seq");
Label lbl3 = (Label)item.FindControl("lbl_dg_repeat1");
Label lbl4 = (Label)item.FindControl("lbl_dg_final1");
RadioButton l1 = (RadioButton)item.FindControl("L1");
RadioButton l2 = (RadioButton)item.FindControl("L2");
RadioButton l3 = (RadioButton)item.FindControl("L3");
RadioButton l4 = (RadioButton)item.FindControl("L4");
RadioButton r1 = (RadioButton)item.FindControl("R1");
RadioButton r2 = (RadioButton)item.FindControl("R2");
RadioButton r3 = (RadioButton)item.FindControl("R3");
RadioButton r4 = (RadioButton)item.FindControl("R4");
AjaxControlToolkit.ModalPopupExtender mpex1 = (AjaxControlToolkit.ModalPopupExtender)item.FindControl("ModalPopupExtender1");
AjaxControlToolkit.ModalPopupExtender mpex2 = (AjaxControlToolkit.ModalPopupExtender)item.FindControl("ModalPopupExtender2");
Button bsr1 = (Button)item.FindControl("btn_saveRep1");
Button bsr2 = (Button)item.FindControl("btn_saveRep2");
Button bsr3 = (Button)item.FindControl("btn_repeat_cnxl1");
Button bsr4 = (Button)item.FindControl("btn_repeat_cnxl2");
//-----------------------------
if (chb.Checked == true)
{
l1.Enabled = false;
l2.Enabled = false;
l3.Enabled = false;
l4.Enabled = false;
r1.Enabled = false;
r2.Enabled = false;
r3.Enabled = false;
r4.Enabled = false;
l1.Checked = false;
l2.Checked = false;
l3.Checked = false;
l4.Checked = false;
r1.Checked = false;
r2.Checked = false;
r3.Checked = false;
r4.Checked = false;
lbl1.CssClass = "grayedout";
lbl2.CssClass = "grayedout";
}
else
{
l1.Enabled = true;
l2.Enabled = true;
l3.Enabled = true;
l4.Enabled = true;
r1.Enabled = true;
r2.Enabled = true;
r3.Enabled = true;
r4.Enabled = true;
lbl1.CssClass = "seq";
lbl2.CssClass = "task";
}
}
}
}
protected void rptr1_OnItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "saveRep1")
{
DropDownList ddl1 = (DropDownList)e.Item.FindControl("ddl_dg_repeat");
RadioButtonList rbl1 = (RadioButtonList)e.Item.FindControl("radio_dg_final");
Label lbl3 = (Label)e.Item.FindControl("lbl_dg_repeat1");
Label lbl4 = (Label)e.Item.FindControl("lbl_dg_final1");
AjaxControlToolkit.ModalPopupExtender mpex2 = (AjaxControlToolkit.ModalPopupExtender)e.Item.FindControl("ModalPopupExtender2");
lbl3.Text = ddl1.SelectedItem.Text;
lbl4.Text = rbl1.SelectedItem.Text;
mpex2.Hide();
rdchk = true;
}
//------------------------------------------------------------
if (e.CommandName == "saveRep2")
{
DropDownList ddl1 = (DropDownList)e.Item.FindControl("ddl_dg_repeat");
RadioButtonList rbl1 = (RadioButtonList)e.Item.FindControl("radio_dg_final");
Label lbl3 = (Label)e.Item.FindControl("lbl_dg_repeat2");
Label lbl4 = (Label)e.Item.FindControl("lbl_dg_final2");
RadioButton l1 = (RadioButton)e.Item.FindControl("L1");
AjaxControlToolkit.ModalPopupExtender mpex2 = (AjaxControlToolkit.ModalPopupExtender)e.Item.FindControl("ModalPopupExtender2");
lbl3.Text = ddl1.SelectedItem.Text;
lbl4.Text = rbl1.SelectedItem.Text;
mpex2.Hide();
rdchk = true;
}
//------------------------------------------------------------
if (e.CommandName == "cnxlRepeat1")
{
AjaxControlToolkit.ModalPopupExtender mpex2 = (AjaxControlToolkit.ModalPopupExtender)e.Item.FindControl("ModalPopupExtender2");
RadioButton l1 = (RadioButton)e.Item.FindControl("L1");
l1.Checked = false;
mpex2.Hide();
}
//------------------------------------------------------------
if (e.CommandName == "cnxlRepeat2")
{
AjaxControlToolkit.ModalPopupExtender mpex2 = (AjaxControlToolkit.ModalPopupExtender)e.Item.FindControl("ModalPopupExtender2");
RadioButton r1 = (RadioButton)e.Item.FindControl("R1");
r1.Checked = false;
mpex2.Hide();
}
//------------------------------------------------------------
if (e.CommandName == "rdown")
{
ListBox lbx1 = (ListBox)e.Item.FindControl("ListBox1");
ListBox lbx2 = (ListBox)e.Item.FindControl("ListBox2");
if (lbx1.SelectedIndex != -1)
{
lbx2.Items.Add(lbx1.SelectedItem);
lbx1.Items.Remove(lbx1.SelectedItem);
lbx2.SelectedIndex = -1;
}
}
//------------------------------------------------------------
if (e.CommandName == "rup")
{
ListBox lbx3 = (ListBox)e.Item.FindControl("ListBox1");
ListBox lbx4 = (ListBox)e.Item.FindControl("ListBox2");
if (lbx4.SelectedIndex != -1)
{
lbx3.Items.Add(lbx4.SelectedItem);
lbx4.Items.Remove(lbx4.SelectedItem);
lbx3.SelectedIndex = -1;
}
}
//----------------------------------------------------------
if (e.CommandName == "ddl3Databound")
{
DropDownList ddlr1 = (DropDownList)e.Item.FindControl("DropDownList3");
ListBox lbx5 = (ListBox)e.Item.FindControl("ListBox1");
lbx5.DataBind();
}
//----------------------------------------------------------
if (e.CommandName == "plus")
{
Panel pnl1 = (Panel)e.Item.FindControl("pnlXtra");
TextBox txtb1 = (TextBox)e.Item.FindControl("txtb_comment");
ImageButton imgb1 = (ImageButton)e.Item.FindControl("imgBtn_xtraPlus");
ImageButton imgb2 = (ImageButton)e.Item.FindControl("imgBtn_xtraMin");
Label lblx1 = (Label)e.Item.FindControl("label2");
lblx1.Text = "after";
imgb1.Visible = false;
imgb2.Visible = true;
pnl1.Visible = true;
}
}
}
}