Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

Please refer to this image

http://s20.postimg.org/54uf2alml/latest.png[^]

What i am trying to do is on selecting date in first textbox. e.g. 14th june 2013,generate the gridview shown there with 5 dates(other dates will be calculated based on selected date in textbox). And below the gridview theres a button.

Code:


protected void BindEmptyGrid()
{
  try
  {
    DataTable dtab = daNewTable();
    DateTime todate_ = Convert.ToDateTime(Session["1"]);
    DateTime fromdate_ = Convert.ToDateTime(Session["2"]);
    TextBox1.Text = ChangeFormat(Convert.ToDateTime(todate_), "dd/MM/yyyy");
    string[] weekdates = new string[5];
    DataRow d = dtab.NewRow();               
    for (DateTime date1 = fromdate_; date1 <= todate_; date1 = date1.AddDays(1))
    {
     DataColumn dc = new DataColumn();
     dc.ColumnName = ChangeFormat(Convert.ToDateTime(date1), "dd-MM-yyyy");
     dtab.Columns.Add(dc);
    }
    dtab.Rows.Add();
    if (weekdates.Length > 0)
    {
     timegrid.DataSource = dtab;
     timegrid.DataBind();
    }
  }
  catch (Exception ex)
  {
    throw ex;
  }
}
public DataTable daNewTable()
{
  DataTable dtempty = new DataTable();           
  return dtempty;
}


But i am facing two problems.

1) I want to have textbox in the generated rows(that is 5 dates),whereas i am getting only empty rows?

2) How to access gridview fields from button_click event where the button is located outside the gridview?

I really appreciate any help in this regard.
Posted

1 solution

Quote:
textbox in the generated rows

how to generate a Row in GridView with TextBoxes[^]

Quote:
How to access gridview fields from button_click event where the button is located outside the gridview?

You can try something like this:
protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in GridView1.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                TextBox textBox = row.FindControl("TextBox1") as TextBox;
                // do somthing with the text box textBox
            }
        }
    }
 
Share this answer
 
Comments
Sejal Rabari 14-Jun-13 3:10am    
Thank you prasad for your response,the solution is good. I came across the link you provided for textbox problem but i have for loop in which i am assigning the values(dates in header)

for (DateTime date1 = fromdate_; date1 <= todate_; date1 = date1.AddDays(1))
{
DataColumn dc = new DataColumn();
dc.ColumnName = ChangeFormat(Convert.ToDateTime(date1), "dd-MM-yyyy");//this line
dtab.Columns.Add(dc);
}

how to integrate that code in this one,i have tried alot since one and half day and i am getting no result.
Sejal Rabari 14-Jun-13 3:42am    
I kindly request you for the resolution as its very important for me.Waiting for your reply at the earliest.Thanks.
Prasad_Kulkarni 14-Jun-13 3:58am    
I am not sure but try something like this and let me know
for (DateTime date1 = fromdate_; date1 <= todate_; date1 = date1.AddDays(1))
{
DataColumn dc = new DataColumn();
dc.ColumnName = ChangeFormat(Convert.ToDateTime(date1), "dd-MM-yyyy");//this line
d[//Your column name where you want text box] = //your textbox.text;
dtab.Columns.Add(dc);
}
Sejal Rabari 14-Jun-13 4:52am    
still doesnt worked. Can you suggest me any other way except gridview. I want to enter just 5 dates and 5 values for that dates.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900