开发者

List<Tuple<T1,T2>> as DataSource for GridView

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 Nameis a string-Property.

He (yes, he, my IDE is called Bob) obviously doesn't find Item1.Name, is there any 开发者_如何学Goway to escape the .?

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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜