Search My Warehouse

2009-12-25

Thumbnail photos in gridview using handler file

thumnail.aspx


<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" Visible="False" Width="50%">

<Columns>
<asp:TemplateField HeaderText="Absentees">
<ItemTemplate>
<asp:CheckBox ID="chk_absentees2" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Photo">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" Height="20px"
ImageUrl='<%# "Handler_Student.ashx?id=" & Eval("stud_id") %>' Width="20px" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="stud_name" HeaderText="Name"
SortExpression="stud_name" />
<asp:BoundField DataField="stud_id" HeaderText="Student ID"
SortExpression="stud_id" />
<asp:BoundField DataField="Course" HeaderText="Course"
SortExpression="Course" />
<asp:BoundField DataField="department" HeaderText="Department"
SortExpression="department" />
<asp:BoundField DataField="stud_year" HeaderText="Year"
SortExpression="stud_year" />
</Columns>
<HeaderStyle HorizontalAlign="Left" />
</asp:GridView>


thumnail.aspx.vb


Public Sub bind_year()

str = Convert.ToString(System.DateTime.Now.ToShortDateString())
If List_dept.Visible = False Then
If List_year.SelectedIndex = -1 Then
Else

lbl_status.Visible = True
btn_absent.Visible = True
lbl_status.Text = List_course.SelectedItem.Text & " " & List_year.SelectedItem.Text & " Year Student Details."

passquery = "select stud_id,stud_name,course,department,stud_year from student_details where course='" & List_course.SelectedValue.ToString() & "' and stud_year='" & List_year.SelectedItem.Text & "' and Joined_in='" & branchid & "' and stud_id not in(select studid from student_attendance where att_date = '" + str + "')"
Call DBConnect(Conn)
Obj.Pr_Bind_Grid(Conn, passquery, GridView1, "No Details available")
If GridView1.Rows.Count = 0 Then
btn_absent.Visible = False
lbl_grid.Visible = True
End If
End If
Else
If List_dept.Text = "" Then
lbl_status.Visible = False
GridView1.Visible = False
btn_absent.Visible = False
Response.Write("<script>alert ('Select Department')</script>")
Else
If List_year.Visible = False Then
Else
If List_year.SelectedIndex = -1 Then
Else


'List_year.SelectedIndex = 0
lbl_status.Visible = True
btn_absent.Visible = True
lbl_status.Text = List_course.SelectedItem.Text & " (" & List_dept.SelectedItem.Text & ") " & List_year.SelectedItem.Text & " Year Student Details."
passquery = "select stud_id,stud_name,course,department,stud_year from student_details where course='" & List_course.SelectedValue.ToString() & "' and department='" & List_dept.SelectedValue.ToString() & "' and stud_year='" & List_year.SelectedItem.Text & "' and Joined_in='" & branchid & "' and stud_id not in(select studid from student_attendance where att_date = '" + str + "')"
Call DBConnect(Conn)
Obj.Pr_Bind_Grid(Conn, passquery, GridView1, "No Details available")
If GridView1.Rows.Count = 0 Then
btn_absent.Visible = False
lbl_grid.Visible = True
End If
End If
End If

End If

End If
GridView1.DataBind()
Conn.Close()
End Sub


Handler_Student.ashx


<%@ WebHandler Language="VB" Class="Handler_Student" %>

Imports System
Imports System.Web
Imports System.Data.SqlClient
Imports System.Configuration

Public Class Handler_Student : Implements IHttpHandler
Dim con As New SqlConnection
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Try
Call DBConnect(con)
Dim sql As String = "Select photo from student_details where stud_id=@staff_id"
Dim cmd As New SqlCommand(sql, con)
cmd.Parameters.Add("@staff_id", System.Data.SqlDbType.VarChar, 50).Value = context.Request.QueryString("id")
cmd.Prepare()
Dim dr As SqlDataReader = cmd.ExecuteReader()
dr.Read()
context.Response.BinaryWrite(DirectCast(dr("photo"), Byte()))
Catch ex As Exception

End Try
End Sub

Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property

End Class

No comments:

Feed