0

我有一个radiobuttonlist我更改了所选项目codebehid

private void DisplayPrivacyTerms(long ImageId)
{
    if (ImageryDataAccess.GetImagePrivacyTerm(ImageId).ToLower() == "me only")
    {
        RadioButtonListPrivacy.Items[0].Selected = true;
    }
    if (ImageryDataAccess.GetImagePrivacyTerm(ImageId).ToLower() == "friends")
    {
        RadioButtonListPrivacy.Items[1].Selected = true;
    }
    if (ImageryDataAccess.GetImagePrivacyTerm(ImageId).ToLower() == "public")
    {
        RadioButtonListPrivacy.Items[2].Selected = true;
    }
}

当所选项目以上方式更改时,然后稍后postback到达服务器会触发selectedindexchanged事件。
特别是我有listview哪些显示器imagebuttons。当我单击中的图像按钮时listview,如果更改了所选项目,则稍后单击图像按钮会触发.. 为什么会发生这种情况,我不希望这会触发此事件selectedinexchanged..radiobuttonlist

4

2 回答 2

0

我不完全确定您要达到的目标。但似乎你需要处理一些关于OnSelectedIndexChanged你的事件的逻辑RadioButtonList

首先将AutoPostBack="true"属性设置在您的RadioButtonList

然后在OnSelectedIndexChanged事件中,写下你的逻辑。

protected void RadioButtonListPrivacy_SelectedIndexChanged(object sender, System.EventArgs e)  
{  
   // your logic here
   // so basically when you click on any of the items in your radiobuttonlist,
   // this event will fire and you can write your logic based on it  
}  
于 2013-04-07T12:37:58.377 回答
0

实际上问题是我已经在 aspx 页面中以声明方式初始化了这些项目。我将有问题的函数更改为如下代码

    private void DisplayPrivacyTerms(long ImageId)
      {
    RadioButtonListPrivacy.Items.Clear();
    ListItem itemMe= new ListItem("Me Only", "1");
    RadioButtonListPrivacy.Items.Add(itemMe);
    ListItem itemMates = new ListItem("Subject Mates", "2");
    RadioButtonListPrivacy.Items.Add(itemMates);
    ListItem itemPublic = new ListItem("Public", "3");
    RadioButtonListPrivacy.Items.Add(itemPublic);

    if (ImageryDataAccess.GetImagePrivacyTerm(ImageId).ToLower() == "me only")
    {
        RadioButtonListPrivacy.Items[0].Selected = true;
    }
    if (ImageryDataAccess.GetImagePrivacyTerm(ImageId).ToLower() == "subject mates")
    {
        RadioButtonListPrivacy.Items[1].Selected = true;
    }
    if (ImageryDataAccess.GetImagePrivacyTerm(ImageId).ToLower() == "public")
    {
        RadioButtonListPrivacy.Items[2].Selected = true;
    }

}

我清除了列表,然后添加了新条目,这样它清除了仅更改 Select=true 属性时出现的视图状态问题.. :)

于 2013-04-07T14:09:45.807 回答