Code Behind Page Page /Controls/UserSearchQuestion.ascx.cs (C#)
Used by Page /Controls/UserSearchQuestion.ascx (C#)
1: using System;  
2: using System.Collections.Generic;  
3: using System.Web.UI;  
4: using System.Web.UI.WebControls;  
5: using QuizNetOnline.Logic;  
6:   
7: namespace QuiznetOnline.Web.UI.Controls  
8: {  
9:     public partial class UserSearchQuestion : UserControl  
10:     {  
11:         public int SelectedQuestionID { get; set; }  
12:         private List<Question> questions;  
13:   
14:         public delegate void AsyncMethodCaller(string txtQuestionSearch, int searchType);  
15:   
16:         protected void Page_Load(object sender, EventArgs e)  
17:         {  
18:             if (!Page.IsPostBack)  
19:             {  
20:                 hiddenUserName.Value = ((UserWeb)Session["userWeb"]).UserName;  
21:   
22:                 AsyncMethodCaller caller = new AsyncMethodCaller(PopulateGrid);  
23:                 //IAsyncResult result = caller.BeginInvoke(txtQuestionSearch.Text,Convert.ToInt32(cmbSearchType.SelectedValue),null, caller);  
24:                 //PopulateGrid(txtQuestionSearch.Text, Convert.ToInt32(cmbSearchType.SelectedValue));  
25:             }  
26:         }  
27:   
28:         protected void CallbackMethod(IAsyncResult ar)  
29:         {  
30:             // Retrieve the delegate.  
31:             AsyncMethodCaller caller = (AsyncMethodCaller)ar.AsyncState;  
32:   
33:             // Call EndInvoke to retrieve the results.  
34:             caller.EndInvoke(ar);  
35:             Session["result"] = ar;  
36:         }  
37:   
38:         private void PopulateGrid(string searchString, int searchOption)  
39:         {  
40:             QuizNetSystem quizNetSystem = new QuizNetSystem();  
41:   
42:             questions = new List<Question>();  
43:             ViewState["questions"] = questions = quizNetSystem.SearchQuestions(searchString,searchOption,100);  
44:   
45:             grdResults.DataSource = questions;  
46:             grdResults.DataBind();  
47:   
48:             UpdatePanel1.Update();  
49:         }  
50:   
51:           
52:         protected void cmdSearch_Click(object sender, EventArgs e)  
53:         {  
54:             PopulateGrid(txtQuestionSearch.Text.Trim(), Convert.ToInt32(cmbSearchType.SelectedValue));  
55:         }  
56:   
57:         public event EventHandler BubbleClick;  
58:         public void OnBubbleClick(EventArgs e)  
59:         {  
60:             if (BubbleClick != null)  
61:             {  
62:                 BubbleClick(this, e);  
63:             }  
64:         }  
65:   
66:         protected void grdResults_RowCommand(object sender, GridViewCommandEventArgs e)  
67:         {  
68:             Page.Validate();  
69:   
70:             if (Page.IsValid)  
71:             {  
72:                 if (e.CommandName.Equals("Select"))  
73:                 {  
74:                     GridViewRow gvr = (GridViewRow)((Control)e.CommandSource).NamingContainer;  
75:                     SelectedQuestionID = Convert.ToInt32(grdResults.DataKeys[gvr.RowIndex].Value);  
76:   
77:                     OnBubbleClick(e);  
78:                 }  
79:             }  
80:         }  
81:   
82:         protected void grdResults_PageIndexChanging(object sender, GridViewPageEventArgs e)  
83:         {  
84:             grdResults.PageIndex = e.NewPageIndex;  
85:             questions = (List<Question>)ViewState["questions"];  
86:             grdResults.DataSource = questions;  
87:             grdResults.DataBind();  
88:         }  
89:     }  
90: }

.NET Documentation Tool is © 2002 - 2009 Winnersh Triangle Web Solutions Limited.