ki_ko Posted May 27, 2008 at 06:27 PM Report Share #187886 Posted May 27, 2008 at 06:27 PM Boas. tenho uma classe que contem no interior uma lista, que esta por si contem mais 2 listas. eu queria listar isto tudo numa gridview. alguem me pode dar uma ajuda? Link to comment Share on other sites More sharing options...
vitortomaz Posted May 27, 2008 at 06:36 PM Report Share #187889 Posted May 27, 2008 at 06:36 PM Já tentaste afectar o DataSource da gridView com essa lista? provavelmente terás que juntar tudo o que queres numa única lista e depois afectar a propriedade DataSource, mas n sei se o resultado será o que pretendes http://vitortomaz.blogspot.com/ Link to comment Share on other sites More sharing options...
ki_ko Posted May 27, 2008 at 06:42 PM Author Report Share #187893 Posted May 27, 2008 at 06:42 PM eu tenho uma classe resultado onde tenho uma List <trajecto>, dentro da classe trajecto tenho mais 2 List <trajectoIda> ,<trajectoVolta>. nao posso correr cada resultado->trajecto->(listaIda e listaVolta) e colocar esses resultado na gridview? se sim, como faço? Link to comment Share on other sites More sharing options...
vitortomaz Posted May 27, 2008 at 06:57 PM Report Share #187894 Posted May 27, 2008 at 06:57 PM estás a usar .net 3.5? já ouviste falar de LINQ ? http://vitortomaz.blogspot.com/ Link to comment Share on other sites More sharing options...
ki_ko Posted May 27, 2008 at 07:02 PM Author Report Share #187897 Posted May 27, 2008 at 07:02 PM tou a usar a 2.0, e nao nunca ouvi falar do LINQ Link to comment Share on other sites More sharing options...
vitortomaz Posted May 27, 2008 at 07:12 PM Report Share #187898 Posted May 27, 2008 at 07:12 PM protected void Page_Load(object sender, EventArgs e) { List<Resultado> list = new List<Resultado>(); Resultado r = new Resultado(); r.MyProperty1=1; r.MyProperty2=22; list.Add(r); list.Add(r); list.Add(r); list.Add(r); list.Add(r); list.Add(r); list.Add(r); list.Add(r); list.Add(r); list.Add(r); list.Add(r); list.Add(r); list.Add(r); list.Add(r); GridView1.DataSource = list; GridView1.DataBind(); } public class Resultado { int i, j, k; public int MyProperty1 { get { return i; } set { i = value; } } public int MyProperty2 { get { return j; } set { j = value; } } public int MyProperty3 { get { return k; } set { k = value; } } } fiz aqui esta brincadeira pa ver se te consigo ajudar... não será a melhor forma de fazeres mas esta já funciona ? criei uma lista de Resultado e afectei a gridview com essa lista [ GridView1.DataSource = list; GridView1.DataBind(); ] agora terás que fazer uns foreach e preencher essa lista com base na tua. isto é uma solução muito fraquita mas de momento é q te posso apresentar... http://vitortomaz.blogspot.com/ Link to comment Share on other sites More sharing options...
ki_ko Posted May 27, 2008 at 07:16 PM Author Report Share #187899 Posted May 27, 2008 at 07:16 PM já é melhor ke nada! thanks. assim que testar se funcionar eu aviso. Link to comment Share on other sites More sharing options...
ki_ko Posted May 27, 2008 at 07:41 PM Author Report Share #187903 Posted May 27, 2008 at 07:41 PM Compiler Error Message: CS0246: The type or namespace name 'List' could not be found (are you missing a using directive or an assembly reference?) Link to comment Share on other sites More sharing options...
vitortomaz Posted May 27, 2008 at 10:30 PM Report Share #187939 Posted May 27, 2008 at 10:30 PM Compiler Error Message: CS0246: The type or namespace name 'List' could not be found (are you missing a using directive or an assembly reference?) Estar a corrigir esse tipo de erro é estar a ensinar o abecedário :s Falta fazer o using System.Collection.Generic ou algo parecido com isso, não estás a usar visual studio? estás a tentar aprender asp.net sozinho em casa? http://vitortomaz.blogspot.com/ Link to comment Share on other sites More sharing options...
ki_ko Posted May 27, 2008 at 10:43 PM Author Report Share #187941 Posted May 27, 2008 at 10:43 PM sim tenho o visual studio. nao, nao tou a aprender em casa. faltava-me o ".generics" Link to comment Share on other sites More sharing options...
vitortomaz Posted May 27, 2008 at 10:51 PM Report Share #187944 Posted May 27, 2008 at 10:51 PM desculpa lá a resposta, é do cansaço http://vitortomaz.blogspot.com/ Link to comment Share on other sites More sharing options...
ki_ko Posted May 27, 2008 at 10:52 PM Author Report Share #187945 Posted May 27, 2008 at 10:52 PM como eu te comprendo!!!! ta-se bem. sempre ajudas-te. Link to comment Share on other sites More sharing options...
ki_ko Posted May 29, 2008 at 12:28 AM Author Report Share #188210 Posted May 29, 2008 at 12:28 AM não estou a conseguir mostrar o gridview, nao dá erro mas nao aparece nada! mesmo que eu faça este exemplo(para testar) no page_load : DataTable dt = new DataTable(); DataColumn dc = new DataColumn("Name"); dt.Columns.Add(dc); DataRow dr = dt.NewRow(); dr["Name"] = "Ivan"; GridView1.DataSource = dt; GridView1.DataBind(); o gridview nao aparece. será que me falta selecionar alguma propriedade que me está a escapar?? Link to comment Share on other sites More sharing options...
vitortomaz Posted May 29, 2008 at 09:20 AM Report Share #188240 Posted May 29, 2008 at 09:20 AM falta adicionar a row à tabela, o NewRow apenas cria uma Row com o mesmo esquema da tabela dt.Rows.Add(dr); http://vitortomaz.blogspot.com/ Link to comment Share on other sites More sharing options...
ki_ko Posted May 29, 2008 at 09:25 AM Author Report Share #188241 Posted May 29, 2008 at 09:25 AM exactamente. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now