简体   繁体   English

如何在TemplateField asp.net中访问gridview值

[英]how to access the gridview values inside the TemplateField asp.net

I want to access the values of gridview which is generated dynamically. 我想访问动态生成的gridview的值。 I want to that values of gridview to copy in datatable but I can not access it. 我想将gridview的值复制到数据表中,但无法访问它。 My code is mention below. 我的代码在下面提到。

DataTable dtCustomers = new DataTable("ShippingDetails");

//Add columns to DataTable.
foreach (TableCell cell in gvShippingBill.HeaderRow.Cells)
{
    dtCustomers.Columns.Add(cell.Text);
}
foreach (GridViewRow row in gvShippingBill.Rows)
{
    dtCustomers.Rows.Add();
    for (int i = 0; i < row.Cells.Count; i++)
    {
        // Console.WriteLine(gvShippingBill.Columns[i].ToString());
        dtCustomers.Rows[row.RowIndex][i] = gvShippingBill.SelectedRow.Cells[i].Text;
        //row.Cells[i].Text;
    }
}

return dtCustomers;
 bind value in lable inside the template filed
 <ItemTemplate>
            <asp:Label ID="Label1" runat="server" Text='<%# Bind("CultivarType") %>'/>
 </ItemTemplate>

 using find control u can get that value
 Label lb = (Label)GridView1.Rows[i].Cells[2].FindControl("Label1");
  string s = lb.Text;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM