Friday 7 December 2012

Get & Set CheckBoxList Selected Item in ASP.net

Use the below Query to Get & Set CheckBoxList Selected Item Using ASP.net

In aspx Page create a CheckBoxList  Example query given below



<asp:CheckBoxList ID="CheckBoxList1" runat="server" RepeatColumns="3">
<asp:ListItem>Mani</asp:ListItem>
<asp:ListItem>Raja</asp:ListItem>
<asp:ListItem>Durai</asp:ListItem>
</asp:CheckBoxList>

Get CheckboxList Selected Item

strCheckedText = "";
  foreach (ListItem LItem in CheckBoxList1.Items)
   {
    string stBool = LItem.Selected.ToString();
    if (stBool == "True")
      {
       if (strCheckedText == "")
       strCheckedText = LItem.Text;
       else
       strCheckedText = strCheckedText + "|" + LItem.Text;

       }
   }


Clear CheckBoxList Selection

 CheckBoxList1.ClearSelection();

Set CheckboxList Selected Item

string[] ss = strCheckedText.Split('|');
 int iq = 0;
 foreach (ListItem LItem in CheckBoxList1.Items)
 {
  for (int i = 0; i < 3; i++)
   {
    if (ss.Length != iq)
     {
      if (LItem.Text == ss[iq])
        {
          LItem.Selected = true;
          iq++;
         }
       }
      }    
    }

 

Create ThumbnailImage Using ASP.net


This article will help you to learn make thumbnail image through the system.  To upload images to the server, we need a File Upload control and a button control. Asp.Net simplifies the process of uploading images to the server with the FileUpload control. To start with, place a FileUpload control and a button control on your webpage like as follows:




<div>
<asp:Label ID="labelMessage" runat="server" Text="Browse Image:" ForeColor="navy"Width="220"></asp:Label>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Upload" runat="server" Text="Upload" OnClick="Upload_Click" />
<asp:Button ID="Button1" runat="server" Text="button" onclick="Button1_Click" />
</div>

<div>
<asp:Label ID="label1" runat="server" Text="Normal Image (Full size): " ForeColor="navy" Width="220"></asp:Label>
<asp:Image ID="NormalImage" runat="server" />
</div>

<div>
<asp:Label ID="label2" runat="server" Text="Thumbnail Small Image (50x50)px: " ForeColor="navy" Width="220"></asp:Label>
<asp:Image ID="ThumbnailImageS" runat="server" />
</div>

<div>
<asp:Label ID="label3" runat="server" Text="Thumbnail Large Image (100x100)px: " ForeColor="navy" Width="220"></asp:Label>
<asp:Image ID="ThumbnailImageM" runat="server" />
</div>


In this article I am using the GetThumbnailImage method of the Image class. This method returns the thumbnail image for the given original image. The syntax for this method is-

public Image GetThumbnailImage(int thumbWidth, int thumbHeight, Image.GetThumbnailImageAbort callback, IntPtr callbackData);

Coading




protected void Upload_Click(object sender, EventArgs e)
    {
FileUpload1.SaveAs(MapPath("~/ImageRaja/" + FileUpload1.FileName));
System.Drawing.Image img1 = System.Drawing.Image.FromFile(MapPath("~/imgRaja/") + FileUpload1.FileName);

System.Drawing.Image bmp1 = img1.GetThumbnailImage(50, 50, null, IntPtr.Zero);
bmp1.Save(MapPath("~/thumbnailRaja/S/") + FileUpload1.FileName);
System.Drawing.Image bmp2 = img1.GetThumbnailImage(100, 100, null, IntPtr.Zero);
bmp2.Save(MapPath("~/thumbnailRaja/L/") + FileUpload1.FileName);
NormalImage.ImageUrl = "~/ ImageRaja /" + FileUpload1.FileName;
ThumbnailImageS.ImageUrl = "~/ thumbnailRaja /S/" + FileUpload1.FileName;
ThumbnailImageM.ImageUrl = "~/ thumbnailRaja /L/" + FileUpload1.FileName;
      }