Hello everybody, I created a general handler which will display names of students. This handler has 2 parameters namely: SchoolCode and term. The first parameter is loaded in my webform on page load. The 2nd parameter is when I type the name of the student in the textbox. Please refer to my code snippet below,
- public void ProcessRequest(HttpContext context)
- {
- string SchoolCode = context.Request["SchoolCode"] ?? "";
- string term = context.Request["term"] ?? "";
- List<string> studentName = new List<string>();
- using (SqlConnection con = DBCS.GetConString())
- {
- SqlCommand cmd = new SqlCommand("spDropdownList_Student", con);
- cmd.CommandType = CommandType.StoredProcedure;
- cmd.Parameters.AddWithValue("@SchoolCode", SchoolCode);
- cmd.Parameters.AddWithValue("@term", term);
- con.Open();
- SqlDataReader rdr = cmd.ExecuteReader();
- while (rdr.Read())
- {
- studentName.Add(rdr["StudentDetails"].ToString());
- }
- }
-
- JavaScriptSerializer js = new JavaScriptSerializer();
- context.Response.Write(js.Serialize(studentName));
- }
Below is my stored proc:
- ALTER PROCEDURE [dbo].[spDropdownList_Student]
-
- @SchoolCode nvarchar(50),
- @term nvarchar(50)
- AS
- BEGIN
-
-
- SET NOCOUNT ON;
-
-
- SELECT
- [Fname] + ' ' + [Lname] + ' - ' + [NickName] as StudentDetails
- FROM [dbo].[tblStudentMaster]
- WHERE [SchoolCode] = @SchoolCode AND [Fname] LIKE @term + '%'
- ORDER BY [Fname] ASC
- END
I tested my sp and it's working fine. Below also is the result:
Now, in my webforms, I made a jquery function to call the handler:
- $(document).ready(function () {
- $('#MasterFileContentSection_txtStudentName').autocomplete({
- source: '/Handlers/StudentName.ashx'
- });
- });
but it didn't display the names of students. I'm new jquery.