Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/10/2015, 13:52
Avatar de laviky65
laviky65
 
Fecha de Ingreso: diciembre-2014
Mensajes: 19
Antigüedad: 9 años, 4 meses
Puntos: 0
Pregunta Generar Checkbox dentro de DataTable

Buenas tardes...
Quisiera saber si hay alguna forma de generar un checkbox dentro de un Datatable para luego poderlo seleccionar.

Estoy manejando unos archivos por un servidor FTP.
Primero listo los archivos que existan en el directorio y luego genero el DataTable para llenar un GridView.

Código C#:
Ver original
  1. try
  2.             {
  3.                 //LISTAR ARCHIVOS
  4.                 FtpWebRequest dirFtp = ((FtpWebRequest)FtpWebRequest.Create(server));
  5.  
  6.                 // Los datos del usuario (credenciales)
  7.                 NetworkCredential cr = new NetworkCredential(usr, pass);
  8.                 dirFtp.Credentials = cr;
  9.  
  10.                 // También usando la enumeración de WebRequestMethods.Ftp
  11.                 dirFtp.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
  12.  
  13.                 //Fetch the Response and read it using StreamReader.
  14.                 FtpWebResponse response = (FtpWebResponse)dirFtp.GetResponse();
  15.                 List<string> entries = new List<string>();
  16.                 using (StreamReader reader = new StreamReader(response.GetResponseStream()))
  17.                 {
  18.                     //Read the Response as String and split using New Line character.
  19.                     entries = reader.ReadToEnd().Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList();
  20.                 }
  21.  
  22.                 // Cerrar el stream abierto.
  23.                 response.Close();
  24.                
  25.                 DataTable dtFiles = new DataTable();
  26.                 dtFiles.Columns.AddRange(new DataColumn[2]
  27.                 {
  28.                     new DataColumn("Name", typeof(string)),
  29.                     new DataColumn("Check", typeof(System.Web.UI.WebControls.CheckBox))
  30.                 });
  31.                
  32.  
  33.                 //Loop and add details of each File to the DataTable.
  34.                 foreach (string entry in entries)
  35.                 {
  36.                     string[] splits = entry.Split(new string[] { " ", }, StringSplitOptions.RemoveEmptyEntries);
  37.  
  38.                     //Determine whether entry is for File or Directory.
  39.                     bool isFile = splits[0].Substring(0, 1) != "d";
  40.                     bool isDirectory = splits[0].Substring(0, 1) == "d";
  41.  
  42.                     //If entry is for File, add details to DataTable.
  43.                     if (isFile)
  44.                     {
  45.                         dtFiles.Rows.Add();
  46.                         DataRow dr = dtFiles.NewRow();
  47.                         System.Web.UI.WebControls.CheckBox ck = new System.Web.UI.WebControls.CheckBox();
  48.                         ck.Checked = false;
  49.                         dr["Check"] = ck;
  50.                         string name = string.Empty;
  51.                         for (int i = 8; i < splits.Length; i++)
  52.                         {
  53.                             name = string.Join(" ", name, splits[i]);
  54.                         }
  55.                         dtFiles.Rows[dtFiles.Rows.Count - 1]["Name"] = name.Trim();
  56.                     }
  57.                 }
  58.                
  59.                 GridView1.DataSource = dtFiles;
  60.                 GridView1.DataBind();
  61.  
  62.             }
  63.             catch (Exception ex)
  64.             {
  65.  
  66.                 throw;
  67.             }


Les confirmo, por cada archivo necesito un CheckBox habilitado para luego poderlo seleccionar...

Hasta ahora no me funciona pero he buscado varias formas de solucionarlo y no he podido por ninguno de los medios...
Si alguien tiene una solución estaría muy agradecida :D

Última edición por laviky65; 27/10/2015 a las 13:53 Razón: Corrección