Gridview Problems.Need帮助。 [英] Gridview Problems.Need help.

查看:91
本文介绍了Gridview Problems.Need帮助。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



请参考此图片



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



我要做的是选择日期第一个文本框。例如2013年6月14日,生成显示的网格视图,其中包含5个日期(其他日期将根据文本框中的选定日期计算)。在gridview下方有一个按钮。



代码:




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;
}





但我面临两个问题。



1)我想在生成的行中有文本框(即5个日期),而我只获得空行?



2)如何访问gridview字段来自button_click事件,其中按钮位于gridview之外?



我非常感谢这方面的任何帮助。



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.

推荐答案

引用:

生成的行中的文本框



如何使用TextBox在GridView中生成一行 [ ^ ]




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

Quote:

如何从button_click事件中访问gridview字段,其中按钮位于gridview之外?

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
            }
        }
    }


这篇关于Gridview Problems.Need帮助。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆