用DateGrid模板列,有一列是textbox 另一列是label 现在要求:
label获取后台传过来的日期,在DateGrid中显示;
把用户输入textbox里的值插入到数据库,要怎么做? 就是说,如何把值传到模板列的控件中去,如何把模板列控件的值传出来!
请给出具体代码!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
谢谢.

解决方案 »

  1.   

    e.Item.Item[Index].FindControl("DataGrid1");       
      

  2.   

    <ItemTemplate>
    <asp:label id=Label1 runat="server" Width="100%" Text='<%# DataBinder.Eval(Container.DataItem,"代理折扣","{0}%") %>'>Label</asp:label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:textbox id=txtDLZK runat="server" Width="100%" Text='<%# DataBinder.Eval(Container.DataItem,"代理折扣") %>'>
    </asp:textbox>
    </EditItemTemplate>private void dg1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    string dlzk=((TextBox) e.Item.FindControl ("txtDLZK")).Text.ToString();
    }
      

  3.   

    tigerwen01(小虎)(编程艺术化)错了,应该是:
    e.Item[Index].FindControl("DataGrid1");
      

  4.   

    for(int i=0;i<DataGrid1.Items.Count;i++)
    {
    string requestName = String.Format("{0}:_ctl{1}:{2}",DataGrid1.ClientID,i+2,"TextBox1");
    Response.Write( Request.Form[ requestName ] );
    Response.Write("<BR>");
    }
      

  5.   

    tigerwen01(小虎)(编程艺术化)错了,应该是:
    e.Item[Index].FindControl("DataGrid1");
    --------------------------
    同意
      

  6.   

    tigerwen01(小虎)(编程艺术化)错了,应该是:
    e.Item[Index].FindControl("DataGrid1");
    --------------------------
    同意写在哪啊!
      

  7.   

    当然根据你的需要,如果是在绑定时候需要得到数值显示
    那就要在DataGrid_ItemDataBound事件中,
    当然录入数据库的事件处理是应该在DataGrid_ItemCommand事件中
      

  8.   

    tigerwen01(小虎)(编程艺术化)错了,应该是:
    e.Item[Index].FindControl("DataGrid1");
    --------------------------
    同意写在哪啊!----------------------------------------------------这样可以吗?应该是e.Item.FindControl("DataGrid1")或e.Item.Cells[Index].FindControl("DataGrid1")吧?
      

  9.   

    假设DataGrid的第一列声明如下
    <asp:HyperLinkColumn DataTextField="au_id" HeaderText="au_id" DataNavigateUrlField="au_id" DataNavigateUrlFormatString="Edit.aspx?id={0}"></asp:HyperLinkColumn>
    读取的时候可以用:
    //Items[0]表示第一行,Cells[0]表示第一列,Controls[0]表示Cell中的第一个控件(也只有这个控件可以用)
    HyperLink link = (HyperLink)DataGrid1.Items[0].Cells[0].Controls[0]);
    Response.Write(link.Text);
    至于模板列(TemplateColumn),当然也可以通过DataGrid1.Items[i].Cells[j].Controls[n]来获取,然后转换成原来的控件类型再操作,但是还有个更好的办法,就是用FindControl来查找控件。
    FindControl是System.Web.UI.Control的方法,可以根据子控件ID来查找子控件
    比如:
    假设DataGrid的某一列声明如下
    <asp:TemplateColumn>
       <ItemTemplate>
          <asp:TextBox Runat="server" ID="txtID" Text='<%# DataBinder.Eval(Container.DataItem,"au_id") %>'>
          </asp:TextBox>
       </ItemTemplate>
    </asp:TemplateColumn>
    读取方法:
    TextBox txt = (TextBox)DataGrid1.Items[1].FindControl("txtID");
    Response.Write(txt.Text);
    注意:DataList中是没有Cell的