I'd like to add a List<Tuple<T1,T2>>
as DataSource
for my GridView
.
"Then do it!"
Yeah, that's not really the problem, the problem is accessing the values inside the GridView.
Here's my Code:
List<Tuple<Group, string>> userGroups = Util.PrepareGroups((string[][])Session["userGroups"]);
gridGroups.DataSource = userGroups;
gridGroups.DataBind();
Throws an exception at DataBind
, telling me that Item1.Name doesn't exist, speaking of this, here's my markup:
<asp:GridView runat="server" ID="gridGroups" CssClass="grid gridGroups" AutoGenerateColumns="false">
<Columns>
<asp:BoundField meta:resourcekey="gridGroupsName" DataField="Item1.Name" />
<asp:BoundField meta:resourcekey="gridGroupsFunction" DataField="Item2" />
</Columns>
</asp:GridView>
Needless to say, Item1
is the Group and Name
is a string
-Property.
.
?
Thanks,
Dennis
Subscribe to the RowDataBound event in your code-behind, that will fire for each row that is bound and you can use the arguments supplied to the event to get at the current data item - you'll find it easier to get at your values that way than trying to mess around with the databinding syntax etc.
(ps - remember to check the rowtype property in your event handler, that's an easy mistake to make - you'll get unexpected results/errors if you're trying to access the data object for a header/footer row! - the link above has some code that demonstrates this)
精彩评论