» Posted by noname at 10/11/2005 21:20:33
» Language: ASPX
« Previous - Next »
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
<%@ Page Language="C#" %>
<%@ Register TagPrefix="wilco" Namespace="Wilco.Web.UI.WebControls" Assembly="Wilco.Web" %>
<script runat="server" language="C#">
class Article
{
private string id;
private string name;
private bool isPublished;
public string ID
{
get
{
return this.id;
}
}
public string Name
{
get
{
return this.name;
}
}
public bool IsPublished
{
get
{
return this.isPublished;
}
}
public Article(string id, string name, bool isPublished)
{
this.id = id;
this.name = name;
this.isPublished = isPublished;
}
}
void Page_Load()
{
if (!this.IsPostBack)
{
Article[] articles = new Article[4];
for (int i = 0; i < articles.Length; i++)
articles[i] = new Article(i.ToString(), "Item " + i, (i % 2) == 0);
this.grid.DataSource = articles;
this.grid.DataBind();
}
}
protected void grid_SelectedIndexChanged(object sender, EventArgs e)
{
this.ShowSelectedItems();
}
protected void button_Click(object sender, EventArgs e)
{
this.ShowSelectedItems();
}
private bool showedContents;
private void ShowSelectedItems()
{
if (this.showedContents)
return;
this.showedContents = true;
foreach (int i in ((Wilco.Web.UI.WebControls.RowSelectorField)this.grid.Columns[0]).SelectedIndices)
{
this.selectedIndices1.Text += "<br />" + i.ToString();
}
foreach (int i in ((Wilco.Web.UI.WebControls.RowSelectorField)this.grid.Columns[1]).SelectedIndices)
{
this.selectedIndices2.Text += "<br />" + i.ToString();
}
foreach (int i in ((Wilco.Web.UI.WebControls.RowSelectorField)this.grid.Columns[2]).SelectedIndices)
{
this.selectedIndices3.Text += "<br />" + i.ToString();
}
foreach (int i in ((Wilco.Web.UI.WebControls.RowSelectorField)this.grid.Columns[3]).SelectedIndices)
{
this.selectedIndices4.Text += "<br />" + i.ToString();
}
}
</script>
<html>
<head>
<title>DataControlFields demo</title>
</head>
<body>
<form runat="server">
<asp:GridView ID="grid" runat="server">
<Columns>
<wilco:RowSelectorField HeaderText="Single, without auto postback" SelectionMode="Single"
AutoPostBack="false" OnSelectedIndexChanged="grid_SelectedIndexChanged" />
<wilco:RowSelectorField HeaderText="Single, with auto postback" SelectionMode="Single"
AutoPostBack="true" OnSelectedIndexChanged="grid_SelectedIndexChanged" />
<wilco:RowSelectorField HeaderText="Multiple, with auto postback" SelectionMode="Multiple"
AutoPostBack="true" OnSelectedIndexChanged="grid_SelectedIndexChanged" />
<wilco:RowSelectorField HeaderText="Multiple, with auto postback, data-bound" SelectionMode="Multiple" DataValueField="IsPublished"
AutoPostBack="true" OnSelectedIndexChanged="grid_SelectedIndexChanged" />
</Columns>
</asp:GridView>
<div>
Selected indices in column 1:
<asp:Label ID="selectedIndices1" runat="server" EnableViewState="False" />
</div>
<div>
Selected indices in column 2:
<asp:Label ID="selectedIndices2" runat="server" EnableViewState="False" />
</div>
<div>
Selected indices in column 3:
<asp:Label ID="selectedIndices3" runat="server" EnableViewState="False" />
</div>
<div>
Selected indices in column 4:
<asp:Label ID="selectedIndices4" runat="server" EnableViewState="False" />
</div>
<div>
<asp:Button ID="button" runat="server" Text="Invoke postback" OnClick="button_Click" />
</div>
</form>
</body>
</html>
|
|