[C#] DataBinding Custom Control

Pagina: 1
Acties:

  • mabarto
  • Registratie: Februari 2001
  • Laatst online: 26-04 19:14
Ik ben bezig met een listview control en wil nu de functionaliteit inbouw om gebruik te maken om een datasource op te geven en hierbij net als de datagrid webcontrol de items te laten tonen.

Nu geef ik het volgende aan mijn custom control:

C#:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<Maraex:ListView 
     ID="ListView" 
     HeaderCssClass="headerListView" 
     ColumnCssClass="columnListView" 
     CellCssClass="cellListView" 
     runat="server"
>
  <Columns>
    <Maraex:ListViewColumn 
         ID="column_id" 
         Name="" 
         Width="40"/>

    <Maraex:ListViewColumn 
         ID="column_image" 
         Name="" 
         Width="30"/>

    <Maraex:ListViewColumn 
         ID="column_name" 
         Name="Naam" 
         Width="150"/>

    <Maraex:ListViewColumn 
         ID="column_title" 
         Name="Titel" 
         Width="225"/>

    <Maraex:ListViewColumn 
         ID="column_type" 
         Name="Type" 
         Width="65"/>

    <Maraex:ListViewColumn 
         ID="column_date" 
         Name="Datum" 
         Width="90"/>

    <Maraex:ListViewColumn 
         ID="column_editor" 
         Name="Bewerkt door" 
         Width="150"/>

  </Columns>
  <Rows>
    <Maraex:ListViewRow>
       
         <Maraex:ListViewItem Value="1" />
         <Maraex:ListViewItem Value="" />
         <Maraex:ListViewItem Value="Index" />
         <Maraex:ListViewItem Value="Timber" />
         <Maraex:ListViewItem Value="Folder" />
         <Maraex:ListViewItem Value="10-10-2003" />
         <Maraex:ListViewItem Value="Pietje" />

    </Maraex:ListViewRow>
    <Maraex:ListViewRow>

         <Maraex:ListViewItem Value="2" />
         <Maraex:ListViewItem Value="" />
         <Maraex:ListViewItem Value="Index" />
         <Maraex:ListViewItem Value="whatever folder" />
         <Maraex:ListViewItem Value="Folder" />
         <Maraex:ListViewItem Value="10-12-2003" />
         <Maraex:ListViewItem Value="Peitje puk" />

    </Maraex:ListViewRow>
  </Rows>
</Maraex:ListView>


In mijn BehindCode onder Page_Load heb ik het volgende:

C#:
1
2
3
ListView.DataSource = 
  myWebService.getContentList(int.Parse(parentId)).Tables[0].DefaultView;
ListView.DataBind();


Nu wil ik net als de datagrid het volgende:

C#:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<Maraex:ListView 
     ID="ListView" 
     HeaderCssClass="headerListView" 
     ColumnCssClass="columnListView" 
     CellCssClass="cellListView" 
     runat="server"
>
  <Columns>
    <Maraex:ListViewColumn 
         ID="column_id" 
         Name="" 
         Width="40"/>

    <Maraex:ListViewColumn 
         ID="column_image" 
         Name="" 
         Width="30"/>

    <Maraex:ListViewColumn 
         ID="column_name" 
         Name="Naam" 
         Width="150"/>

    <Maraex:ListViewColumn 
         ID="column_title" 
         Name="Titel" 
         Width="225"/>

    <Maraex:ListViewColumn 
         ID="column_type" 
         Name="Type" 
         Width="65"/>

    <Maraex:ListViewColumn 
         ID="column_date" 
         Name="Datum" 
         Width="90"/>

    <Maraex:ListViewColumn 
         ID="column_editor" 
         Name="Bewerkt door" 
         Width="150"/>

  </Columns>
  <Rows>
    <Maraex:ListViewRow>
       
         <Maraex:ListViewItem 
            Value='<%# DataBinder.Eval(Container.DataItem, "id")%>' 
         />

         <Maraex:ListViewItem 
            Value="" 
         />

         <Maraex:ListViewItem 
            Value='<%# DataBinder.Eval(Container.DataItem, "name")%>' 
         />

         <Maraex:ListViewItem 
            Value='<%# DataBinder.Eval(Container.DataItem, "title")%>' 
         />

         <Maraex:ListViewItem 
            Value='<%# DataBinder.Eval(Container.DataItem, "type")%>' 
         />

         <Maraex:ListViewItem 
            Value='<%# DataBinder.Eval(Container.DataItem, "date")%>' 
         />

         <Maraex:ListViewItem 
            Value='<%# DataBinder.Eval(Container.DataItem, "editor")%>' 
         />

    </Maraex:ListViewRow>
  </Rows>
</Maraex:ListView>


Mijn vraag is dus hoe je dit kan implementeren in je eigen custom control zodat je die DataBind.Eval(Container.DataItem, "id") uit kan lezen.

Hopend dat iemand mij op weg kan helpen met een voorbeeld hoe dit te implementeren is.

[ Voor 34% gewijzigd door mabarto op 13-10-2003 13:41 . Reden: Tabs weggehaald voor beter leesbaarheid ]


  • EfBe
  • Registratie: Januari 2000
  • Niet online
Haal aub die tabs even voor die tags weg en druk een paar keer op Enter. je posting is nauwelijks leesbaar zo met die lange regels.

Creator of: LLBLGen Pro | Camera mods for games
Photography portfolio: https://fransbouma.com


  • PhoneTech
  • Registratie: Mei 2000
  • Laatst online: 18-08 14:38
Ik denk dat het makkelijker is om jou usercontrol in de code behind te configureren.

Als ik met ASP.NET bezig ben, dan bouw ik bijna altijd de pagiuan op in de code behind...Heb het idee namelijk dat ik meer controle heb over de code...

  • mabarto
  • Registratie: Februari 2001
  • Laatst online: 26-04 19:14
EfBe schreef op 13 October 2003 @ 13:04:
Haal aub die tabs even voor die tags weg en druk een paar keer op Enter. je posting is nauwelijks leesbaar zo met die lange regels.
Done.
PhoneTech schreef op 13 October 2003 @ 13:23:
Ik denk dat het makkelijker is om jou usercontrol in de code behind te configureren.

Als ik met ASP.NET bezig ben, dan bouw ik bijna altijd de pagiuan op in de code behind...Heb het idee namelijk dat ik meer controle heb over de code...
Dat is ook mogelijk maar vind het zelf overzichterlijker op deze manier.

Maar weet iemand hoe ik databinding implementeer in je
eigen custom control?

  • LoekD
  • Registratie: Augustus 2000
  • Laatst online: 09-08 16:24
Is dit iets voor je?

ms-help://MS.NETFrameworkSDK/cpref/html/frlrfsystemwebuiwebcontrolsbasedatalistclasstopic.htm

loading...