My Profile

Sunday, February 6, 2011

ASP.Net Image control

Displaying Images using HTML <img> tag and ASP.Net "Image" control


If we want to display a simple image with no functionality like logo, title image etc., then we can use HTML <img> only.


If we want to programatically refer image from server side code then we have to use ASP.Net "Image" control.


let's see an example to make it clear.


Before seeing example, we should see RadioButton control, which we are going to use in the example


RadioButton:


To accept a value by providing list of options in the form of radio buttons we use this control. Radio Buttons are preferably used for limited options.


In ASP.Net, every radio button represents one group. If we want set of radio buttons to form a single group then explicitly we must group them using "GroupName" property.


Code is written again for every individual selection. Every button is referred directly with its name/id. 




Example: 



  • Design the form as below.

  • Coding
     Under Button Click:

        BLstRes.Items.Clear();
        BLstRes.Visible = true;
        BLstRes.Items.Add("Account No: " + TxtAccNo.Text);
        BLstRes.Items.Add("Name: " + TxtName.Text);
        BLstRes.Items.Add("Amount: " + TxtAmount.Text);
        if (RadCredit.Checked)
        {
            ImgPayMode.Visible = true;
            BLstRes.Items.Add("Payment Mode : " + RadCredit.Text);
            if(LstBanks.SelectedIndex >= 0)
                BLstRes.Items.Add("Bank : " + LstBanks.SelectedValue);
            else
                BLstRes.Items.Add("Bank : Not Selected");
            ImgPayMode.ImageUrl = "~/Images/visa-classic-credit-card.jpg";
        }
        else if (RadDebit.Checked)
        {
            ImgPayMode.Visible = true;
            BLstRes.Items.Add("Payment Mode : " + RadDebit.Text);
            if (LstBanks.SelectedIndex >= 0)
                BLstRes.Items.Add("Bank : " + LstBanks.SelectedValue);
            else
                BLstRes.Items.Add("Bank : Not Selected");
            ImgPayMode.ImageUrl = "~/Images/081031-debit-card-hmed-1p.grid-6x2.jpg";
        }
        else if (RadOnline.Checked)
        {
            ImgPayMode.Visible = true;
            BLstRes.Items.Add("Payment Mode : " + RadOnline.Text);
            if (LstBanks.SelectedIndex >= 0)
                BLstRes.Items.Add("Bank : " + LstBanks.SelectedValue);
            else
                BLstRes.Items.Add("Bank : Not Selected");
            ImgPayMode.ImageUrl = "~/Images/online-banking-1.jpg";
        }
        else if (radCash.Checked)
        {
            ImgPayMode.Visible = true;
            BLstRes.Items.Add("Payment Mode : " + radCash.Text);
            if (LstBanks.SelectedIndex >= 0)
                BLstRes.Items.Add("Bank : " + LstBanks.SelectedValue);
            else
                BLstRes.Items.Add("Bank : Not Selected");
            ImgPayMode.ImageUrl = "~/Images/cash.jpg";
        }
        else
            BLstRes.Items.Add("Mode of Payment Not selected");



----------------------------------------------------------

** If you like this post please like our page in facebook



0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More