Mas

Mas

  • NA
  • 478
  • 71.3k

How can i search the records based on Job Id and job title

Apr 13 2020 12:22 AM
Hello Memebers,
 
Here I am trying to seach the records based on Job title and job-ID...
 
 
 
Can any one guide me, Thank you in advance!!
 
Below is the ASPX code:
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="tquestion.Default" %>  
  2. <!DOCTYPE html>  
  3. <html xmlns="http://www.w3.org/1999/xhtml">  
  4. <head runat="server">  
  5. <title></title>  
  6. <style>  
  7. .text,#GridView1{  
  8. font-family:'Segoe UI';  
  9. font-size:11px;  
  10. }  
  11. </style>  
  12. </head>  
  13. <body>  
  14. <form id="form1" runat="server">  
  15. <div style="margin-left:100px;">  
  16. <table style="width:600px; height:100px;">  
  17. <tr>  
  18. <td>  
  19. <asp:Label ID="lblconsucttechscreen" runat="server" Font-Size="12px" Text="<b>Conduct tech screens</b>"></asp:Label>  
  20. </td>  
  21. </tr>  
  22. <br />  
  23. <tr class="content-text"><td>  
  24. <asp:Label ID="lblloadquestions" runat="server" Font-Size="11px" Width="132px" Text="Load questions from template"></asp:Label>  
  25. <asp:TextBox ID="txtrolename" runat="server" Width="370px" placeholder="Type role name"></asp:TextBox>  
  26. <asp:Button ID="btnload" runat="server" Text="Load" Width="65px" Height="25px" style="background-color:darkblue; color:white; font-family:'Segoe UI'; font-size:11px; border:1px solid #DCDCDC" OnClick="btnload_Click" />  
  27. </td></tr>  
  28. <tr class="content-text"><td>  
  29. <asp:Label ID="lbljobid" runat="server" Font-Size="11px" Width="132px" Text="Load questions from template"></asp:Label>  
  30. <asp:TextBox ID="txtjobid" runat="server" Width="370px" placeholder="Type job-id"></asp:TextBox>  
  31. <asp:Button ID="btnload1" runat="server" Text="Load" Width="65px" Height="25px" style="background-color:darkblue; color:white; font-family:'Segoe UI'; font-size:11px; border:1px solid #DCDCDC" OnClick="btnload_Click" />  
  32. </td></tr>  
  33. </div>  
  34. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" HeaderStyle-ForeColor="White" HeaderStyle-BackColor="#000099" >  
  35. <Columns>  
  36. <asp:BoundField ItemStyle-Width="50px" DataField="job_id" HeaderText="Job-id" />  
  37. <asp:HyperLinkField DataTextField="Jobtitle" ItemStyle-Width="90px" HeaderText="Job title" SortExpression="Jobtitle" />  
  38. <asp:BoundField ItemStyle-Width="245px" DataField="Jobdescription" HeaderText="Job description" />  
  39. <asp:BoundField ItemStyle-Width="65px" DataField="createdby" HeaderText="Created by" />  
  40. <asp:BoundField ItemStyle-Width="120px" DataField="createddate" HeaderText="Created date" />  
  41. </Columns>  
  42. </asp:GridView>  
  43. </form>  
  44. </body>  
  45. </html>
CS code:
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7. using MySql.Data.MySqlClient;  
  8. using System.Data;  
  9. using System.Configuration;  
  10. namespace tquestion  
  11. {  
  12. public partial class Default : System.Web.UI.Page  
  13. {  
  14. protected void Page_Load(object sender, EventArgs e)  
  15. {  
  16. if (!this.IsPostBack)  
  17. {  
  18. this.BindGrid();  
  19. }  
  20. }  
  21. private void BindGrid()  
  22. {  
  23. string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;  
  24. using (MySqlConnection con = new MySqlConnection(constr))  
  25. {  
  26. using (MySqlCommand cmd = new MySqlCommand("SELECT job_id,Jobtitle, Jobdescription, createdby, createddate FROM questions"))  
  27. {  
  28. using (MySqlDataAdapter sda = new MySqlDataAdapter())  
  29. {  
  30. cmd.Connection = con;  
  31. sda.SelectCommand = cmd;  
  32. using (DataTable dt = new DataTable())  
  33. {  
  34. sda.Fill(dt);  
  35. GridView1.DataSource = dt;  
  36. GridView1.DataBind();  
  37. }  
  38. }  
  39. }  
  40. }  
  41. }  
  42. protected void OnPaging(object sender, GridViewPageEventArgs e)  
  43. {  
  44. GridView1.PageIndex = e.NewPageIndex;  
  45. this.BindGrid();  
  46. }  
  47. protected void btnload_Click(object sender, EventArgs e)  
  48. {  
  49. string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;  
  50. using (MySqlConnection con = new MySqlConnection(constr))  
  51. {  
  52. using (MySqlCommand cmd = new MySqlCommand("SELECT * FROM questions WHERE Jobtitle = '@Jobtitle';"))  
  53. {  
  54. cmd.CommandType = CommandType.Text;  
  55. cmd.Connection = con;  
  56. con.Open();  
  57. using (MySqlDataReader sdr = cmd.ExecuteReader())  
  58. {  
  59. sdr.Read();  
  60. txtrolename.Text = sdr["Jobtitle"].ToString();  
  61. }  
  62. con.Close();  
  63. }  
  64. }  
  65. }  
  66. }  


Answers (6)