I'm trying to rescue the ID
from my client that is in GridView
, but I'm using DataTable
to fill GridView
.
DataTable
public DataTable SelecionarDT()
{
objDAO = new ClienteDAO();
DataRow dr;
DataTable dt = new DataTable();
IList<Cliente> lista = new List<Cliente>();
dt.Columns.Add("ID");
dt.Columns.Add("Nome");
dt.Columns.Add("CPF/CNPJ");
dt.Columns.Add("Telefone");
lista = objDAO.Buscar();
if (lista != null)
{
foreach (Cliente cliente in lista)
{
dt.DefaultView.Sort = "Nome";
dr = dt.NewRow();
dr["ID"]= cliente._ClienteID;
dr["Nome"] = cliente._Nome;
dr["CPF/CNPJ"] = cliente._Cpf_cnpj;
dr["Telefone"] = cliente._Telefone;
dt.Rows.Add(dr);
}
}
return dt;
}
This is GridView
<asp:GridView ID="gdvCliente" runat="server" CssClass="table table-condensed" AllowPaging="True" CellPadding="4" ForeColor="#333333" GridLines="None" OnPageIndexChanging="gdvCliente_PageIndexChanging" PageSize="5" DataKeyNames="ID" OnRowCommand="gdvCliente_RowCommand">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField EditText="" SelectText="" ShowSelectButton="True" ControlStyle-CssClass="glyphicon glyphicon-edit" ControlStyle-Width="1" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle CssClass="" BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>