Code
Id Emp_Id Category_Id
1 sss A
2 CCC A
3 VVV B
4 BBB BHide Copy Code
Code
Int16 day = Convert.ToInt16(SafeConvert.ToDateTime(txtDate.Text).Day);Id Emp_Id Category_Id
1 sss A
2 CCC A
3 VVV B
4 BBB B Int16 day = Convert.ToInt16(SafeConvert.ToDateTime(txtDate.Text).Day);Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Syed ShanuRank #87 · 23.7K reputationPosted Apr 5, 2015, 10:25 PM EDT
kiinly check the attached sample Source Program.In the Attached file Check for the Form2.Your solution is placed in Form2.
here is my code looks like.I have created using Winform.This can be used in both Win and Web form
Step 1) Add Datetime Picker,Button and datagridview Control to your form .
IN Form Load event.
DataTable DTable = new DataTable();
private void Form2_Load(object sender, EventArgs e)
{
//ServersTable - DataGridView
DTable.Columns.Add(new DataColumn("ID"));
DTable.Columns.Add(new DataColumn("Emp_Id"));
DTable.Columns.Add(new DataColumn("Category_Id"));
DataRow r = DTable.NewRow();
r.BeginEdit();
r["ID"] = "1";//writing values
r["Emp_Id"] = "SS";//writing values
r["Category_Id"] = "AA";//writing values
r.EndEdit();
DTable.Rows.Add(r);
r = DTable.NewRow();
r.BeginEdit();
r["ID"] = "2";//writing values
r["Emp_Id"] = "VV";//writing values
r["Category_Id"] = "AA";//writing values
r.EndEdit();
DTable.Rows.Add(r);
r = DTable.NewRow();
r.BeginEdit();
r["ID"] = "3";//writing values
r["Emp_Id"] = "KK";//writing values
r["Category_Id"] = "BB";//writing values
r.EndEdit();
DTable.Rows.Add(r);
r = DTable.NewRow();
r.BeginEdit();
r["ID"] = "4";//writing values
r["Emp_Id"] = "ZZ";//writing values
r["Category_Id"] = "BB";//writing values
r.EndEdit();
DTable.Rows.Add(r);
}
In Button Click
private void button1_Click(object sender, EventArgs e)
{
int value = Convert.ToInt32(dateTimePicker1.Value.Date.ToString("dd"));
string expression = "Category_Id = 'AA'";
if (value % 2 != 0)
{
expression = "Category_Id = 'AA'";
}
else
{
expression = "Category_Id = 'BB'";
}
DataView dv = new DataView(DTable);
dv.RowFilter = expression; // query example = "id = 10"
dataGridView1.DataSource = dv;
}
Sajid HussainRank #3,026 · 476 reputationPosted Apr 6, 2015, 12:06 AM EDT
Syed ShanuRank #87 · 23.7K reputationPosted Apr 6, 2015, 12:20 AM EDT
Gowtham RajamanickamRank #57 · 29K reputationPosted Apr 6, 2015, 12:26 AM EDT
Sajid HussainRank #3,026 · 476 reputationPosted Apr 6, 2015, 12:57 AM EDT