Wednesday, February 2, 2011

The Search Form (Code Behind)

 

 protected void ButtonSearch_Click(object sender, EventArgs e)
{
string criterias = "";

criterias = TextBoxKeyword.Text.Length > 0 ? (criterias + "Keyword") : criterias;
criterias = TextBoxCourse.Text.Length > 0 ? (criterias + "Course") : criterias;
criterias = TextBoxStartDate.Text.Length > 0 ? (criterias + "EventDate") : criterias;
criterias = TextBoxDateOfEntryStart.Text.Length > 0 ? (criterias + "DateOfEntry") : criterias;


string keyword = TextBoxKeyword.Text.Length>0? TextBoxKeyword.Text : "NULL";
string course = TextBoxCourse.Text.Length > 0 ? TextBoxCourse.Text : "NULL";
string startdate = TextBoxStartDate.Text.Length > 0 ? TextBoxStartDate.Text : "NULL";
string enddate = TextBoxEndDate.Text.Length > 0 ? TextBoxEndDate.Text : "NULL";
string dateofentrystart = TextBoxDateOfEntryStart.Text.Length > 0 ? TextBoxDateOfEntryStart.Text : "NULL";
string dateofentryend = TextBoxDateOfEntryEnd.Text.Length > 0 ? TextBoxDateOfEntryEnd.Text : "NULL";

TextBox1.Text = "Criterias:" + criterias + "\nKeyword:" + keyword + "\nCourse:" + course
+ "\nStartDate:" + startdate + "\nEndDate:" + enddate
+ "\nDateOfEntryStart:" + dateofentrystart + "\nDateOfEntryEnd:" + dateofentryend;

SqlDataSourceEventsByCriteria.SelectParameters["Criteria"].DefaultValue = criterias;
SqlDataSourceEventsByCriteria.SelectParameters["Keyword"].DefaultValue = keyword;
SqlDataSourceEventsByCriteria.SelectParameters["Course"].DefaultValue = course;
SqlDataSourceEventsByCriteria.SelectParameters["EventStartDate"].DefaultValue = startdate;
SqlDataSourceEventsByCriteria.SelectParameters["EventEndDate"].DefaultValue = enddate;
SqlDataSourceEventsByCriteria.SelectParameters["DateOfEntryStart"].DefaultValue = dateofentrystart;
SqlDataSourceEventsByCriteria.SelectParameters["DateOfEntryEnd"].DefaultValue = dateofentryend;

try
{

DataView dvEvents = (DataView)SqlDataSourceEventsByCriteria.Select(DataSourceSelectArguments.Empty);
DataTable dtEvents = dvEvents.Table;
GridView1.DataSource = dtEvents;
GridView1.DataBind();
}
catch (Exception exSelect)
{
TextBox1.Text = exSelect.Message;
}
}

No comments: