1

I want to display same data in between for a range of 2 dates for C# asp.net using DataBound gridview in asp.net c#

example in the image, i want to display the data in between 21-Nov-2013 until 29-Nov-2013 that all the dates in between have the country name Indonesia.

I used int i = e.Row.RowIndex; to capture the current index whr it is match with the date for 21-Nov-2013, int j = e.Row.RowIndex; for 29-Nov-2013.

if (e.Row.Cells[0].Text == "21-Nov-2013")
{
    int i = e.Row.RowIndex;
    e.Row.Cells[2].Text = "Indonesia";
}
else if (e.Row.Cells[0].Text == "29-Nov-2013")
{
    int j = e.Row.RowIndex;
    e.Row.Cells[2].Text = "Indonesia";
}
else {}

for(i;i<j;i++)
gridview1.Rows[i].Cells[2].Text = "Indonesia";

enter image description here

slavoo
  • 5,798
  • 64
  • 37
  • 39

2 Answers2

1

the date that u writen it's not comparable so,first you should convert your date ("21-Nov-2013") to comparable value. save value of

e.Row.Cells[0].Text in b instead of "21-Nov-2013".

 string month = "1";
            string b = "21-Nov-2013";
            string day = b.Substring(0, 2);
            switch (b.Substring(3,3))
            {
                case "Jun":
                    month = "1";
                    break;

                case "Feb":
                    month = "2";
                    break;
                    /*other month
                     * 
                     * */
                case "Nov":
                    month = "11";
                    break;

            }
            int date=Convert.ToInt32(day+month+b.Substring(7,4));
//compare (daymonthyear)
            if (date >= 21112013 && date<=21112013)
            {

                int i = e.Row.RowIndex;
                e.Row.Cells[2].Text = "Indonesia";

                  }

plz complete switch case for other month

0
if (e.Row.Cells[0].Text >= "21-Nov-2013" && e.Row.Cells[0].Text <= "29-Nov-2013")
{
    int i = e.Row.RowIndex;
    e.Row.Cells[2].Text = "Indonesia";
}

u should use &&(and) in u'r loop.it's true when both side of condition be

reza jafari
  • 1,228
  • 13
  • 14