ASP.NET使用Eval functinon生成ID

时间:2015-03-05 15:40:18

标签: c# asp.net gridview hyperlink eval

对于GridView中的每一行,我都有一个HyperLink,我需要为每个行生成不同的ID。使用Eval无法正常工作:

<asp:GridView
                ID="ResultTableGvw"
                runat="server"
                AutoGenerateColumns="false"
                OnRowDataBound="ResultTableGvw_RowDataBound">
                <Columns>
                    <asp:BoundField ReadOnly="true" HeaderText="ID" DataField="id" />
                    <asp:BoundField ReadOnly="true" HeaderText="accountId" DataField="externalId" />
                    <asp:BoundField ReadOnly="true" HeaderText="tydeId" DataField="typeId" />
                    <asp:BoundField ReadOnly="true" HeaderText="Estado" DataField="statusId" />
                    <asp:BoundField ReadOnly="true" HeaderText="Timestamp do Pedido" DataField="timestampRequest" />
                    <asp:TemplateField HeaderText="Operação" ItemStyle-Wrap="false">
                        <ItemTemplate>
                            <asp:HyperLink
                                ID='<%# DataBinder.Eval( Container.DataItem, "Id", "OperationManagementHl{0}") %>'
                                runat="server"
                                Text="">
                            </asp:HyperLink>
                        </ItemTemplate>
                        <ItemStyle Wrap="False"></ItemStyle>
                    </asp:TemplateField>

                </Columns>
            </asp:GridView>

有任何解决这个问题的建议吗?

错误是:The ID property of a control can only be set using the ID attribute in the tag and a simple value. Example: <asp:Button runat="server" id="Button1" />

1 个答案:

答案 0 :(得分:0)

尝试使用此模式,它适用于我,

<asp:Label ID="lblNames" runat="server" Text='<%# Eval("Names") %>'  Height ="60px" Width ="90%"    CssClass="LabelDesign"   />