开发者

add image dynamiacally based on count in ASP.NET

suppose I have 5 check boxes. Based on number of check box checked I have to add image and hyper-link to images. (i.e if I have checked 2 check box I have to load only 2 image and link to those 2 loaded images, in-case of 3 check box checked, 3 images needs to be loaded and link to those 3 loa开发者_JAVA百科ded images).

Is there any possible way that I can do that in asp.net using c#?


If you want to display images or hide right after you select or deselect a check box you need to set the AutoPostBack attribute of the checkboxes controls (or checkboxlist control) to true.

And in the respective OnSelectedIndexChanged event (or the Button1_Click event if that's the case) you simply change the images Visible property to true or false depeding on the options selected.

Also, if you want the user experience to be smoother you may embedd your images markup inside an UpdatePanel and call:

UpdatePanel1.Update();

Got it?


It depends on whether the CheckBoxes are in a CheckBoxList, but assuming they're not put the CheckBoxes in some type of parent container, i.e. a PlaceHolder or a Panel, and you can retrieve the CheckBoxes like this:

foreach (CheckBox chk in PlaceHolder1.Controls.OfType<CheckBox>())
{
    if (chk.Checked)
    {
        //create/load image and hyperlink            
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜