In this article i discuss about to resize an image on file upload control..
Normally if the image has more size it will occupy more bytes,so better we have to resize the image for our appropriate needs..
Even if you would like to show image as thumbnail,in such case  its better resize to small size then only images looks good.
In an previous post I discuss about to validate the uploaded images and save the images indatabase,now there is no need to describe it,so we I share the code directly to resize the image.





Below just pass the fileupload control to the fuction..
This the simple code to resize the image ..
Function resize(ByRef flp As FileUpload)
        '*****************www.dotnetcode.in************
        Dim height As String = "62"
        Dim width As String = "105"
        If flp.HasFile Then
            Dim myimg As System.Drawing.Image
            myimg = System.Drawing.Image.FromStream(flp.PostedFile.InputStream)
            myimg = myimg.GetThumbnailImage("105", "62", Nothing, IntPtr.Zero)
            Dim str As New MemoryStream
            myimg.Save(str, System.Drawing.Imaging.ImageFormat.Jpeg)

            Dim conbyt As Byte() = New Byte(str.Length - 1) {}
            str.Position = 0
            str.Read(conbyt, 0, conbyt.Length)
            Return conbyt
        End If
    End Function

Finally we return the images as byte, so we can easily save the bytes into Database.
In case if you want save into local path ..
myimg.Save("C:\Users\admin\Pictures\car\1.jpg", myimg.RawFormat)
IF you add some graphics to the image then you have to follow the below code.


Dim bmpOut As New System.Drawing.Bitmap(NewWidth, NewHeight)
    Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(bmpOut)
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
            g.FillRectangle(System.Drawing.Brushes.White, 0, 0, NewWidth, NewHeight)
            g.DrawImage(New System.Drawing.Bitmap(flp.PostedFile.InputStream), 0, 0, NewWidth, NewHeight)
    Dim str As New MemoryStream()
            myimg.Save(str, System.Drawing.Imaging.ImageFormat.Jpeg)


Then the resize image has resized with better quality.
I hope you like this article…..keep reading


Introduction:
Article about to use radio button inside listview..Recently i had an option work with radio button inside listview, Normally i always prefer to use JavaScript to make single selection
in radio button, in my case listview control unable to find in javascript really i got frustrated to make to find listview in script. Finally i done the code in server side and accomblish my needs.
Here i share the code to make single selection as radio button inside listview

Code:

Radiobutton inside listview..
<ItemTemplate>
<asp:RadioButton ID="rdb" runat="server" Text='<%#Eval("CARDESC")%>' AutoPostBack="true"   OnCheckedChanged="rdbSelect_Changed"/>
</ItemTemplate>

Server code onchecked change event..
Protected Sub rdb_Changed(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim rb1 As RadioButton = CType(sender, RadioButton)

        For Each row As ListViewItem In lstvwdet.Items
            Dim rb As RadioButton = row.FindControl("rdb")
            If rb IsNot Nothing AndAlso rb.Checked Then
                rb.Checked = False
            End If
        Next
        rb1.Checked = True
    End Sub

In case if you have need to get the selected radio button text  in outside button use the below code to find the selected radio button text
For Each row As ListViewItem In lstvwdet.Items
            Dim rb As RadioButton = row.FindControl("rdb")
            If rb.Checked = True Then
                Str = rb.Text
            End If
        Next

Keep reading……..


In this article about to pick the selected row data from gridview using javascript.

Inside gridview i added one html checkbox, when the user select any  checkbox ,on click event we call the javascript and show the selected column value using alert, it’s very simple process. on click event we pass the row item index, by using row index we can easily get selected  any row column values.
By getting column values using rowindex can achieve only if we use Bound field in gridview..


Code:
   <script type="text/javascript">
        function chng(t, obj) {
            if (obj.checked == true) {
                var CellValue, cell, tj;
                var table = document.getElementById('<%=GridView1.ClientID %>');
                cell = document.getElementById('<%=GridView1.ClientID %>').rows[parseInt(t) + 1].cells[1];
                tj = cell.innerHTML;
                alert(tj);
            }
        }

    </script>

<asp:GridView ID="GridView1" AutoGenerateColumns="False" AutoGenerateSelectButton="false"
        AllowPaging="True" SelectedIndex="1" AllowSorting="true"
runat="server">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <input type="checkbox" value="getIndex" onclick="chng(<%# Container.DataItemIndex %>,this);" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Name" HeaderText="Name" InsertVisible="False" ReadOnly="True"
                SortExpression="Name" />
            <asp:BoundField DataField="roll" HeaderText="Address" SortExpression="Address" />
        </Columns>
        <SelectedRowStyle BackColor="LightCyan" ForeColor="DarkBlue" Font-Bold="true" />
    </asp:GridView>

Above code works perfectly, In an alert window its show the selected value from the grid view..
I hope it’s helpful…keep reading