如何将项模板(eval)值分配给asp.net gridview控件之外的标签

时间:2013-06-13 18:43:22

标签: c# asp.net visual-studio-2010

我想分配

<%# DataBinder.Eval(Container.DataItem, "Name")%>

在gridview中的标签

 Label2

在gridview之外。我不知道如何做到这一点,因为Eval值在Gridview和我之内 需要在gridview之外使用它。我有以下代码。

请告诉我。

<div class="ModalPopup" id="PopupDiv1">
            <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                <ContentTemplate>
                    <table>
                        <tr>
                            <td>
                                <div class="modalHeader">
                                    <table width="100%">
                                        <tr>
                                            <td class="title">
                                                <asp:Label ID="Label2" Font-Bold="true" runat="server"></asp:Label>
                                            </td>
                                            <td>
                                                <a href="javascript:void(0);" onclick="javascript:CloseModelPopup1();" class="CloseModal">
                                                    X</a>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div id="Div1" class="InsertBar">
                                    <asp:Panel ID="Panel1" runat="server" HorizontalAlign="left" ScrollBars="Auto">
                                        <asp:GridView ID="gDetails" OnRowDataBound="gvDetails_RowDataBound"
                                         Orunat="server" CellPadding="5" 
                                            AutoGenerateColumns="false">
                                            <Columns>
                                                <asp:TemplateField>
                                                    <ItemTemplate>
                                                        <asp:Image Width="32px" ID="statusImage" runat="server" Height="32px"></asp:Image>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="LogId">
                                                    <ItemTemplate>
                                                        <%# DataBinder.Eval(Container.DataItem, "LogId") %>
                                                  </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="Name">
                                                    <ItemTemplate>
                                                        <%# DataBinder.Eval(Container.DataItem, "Name")%>        </ItemTemplate>
                                                </asp:TemplateField>
                                             </Columns>
                                        </asp:GridView>
                                    </asp:Panel>
                                </div>
                            </td>
                        </tr>
                    </table>
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>

1 个答案:

答案 0 :(得分:0)

    Try this out

<div class="ModalPopup" id="PopupDiv1">
            <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                <ContentTemplate>
                    <table>
                        <tr>
                            <td>
                                <div class="modalHeader">
                                    <table width="100%">
                                        <tr>
                                            <td class="title">
                                                <asp:Label ID="Label2" Font-Bold="true" runat="server"></asp:Label>
                                            </td>
                                            <td>
                                                <a href="javascript:void(0);" onclick="javascript:CloseModelPopup1();" class="CloseModal">
                                                    X</a>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div id="Div1" class="InsertBar">
                                    <asp:Panel ID="Panel1" runat="server" HorizontalAlign="left" ScrollBars="Auto">
                                        <asp:GridView ID="gDetails" OnRowDataBound="gvDetails_RowDataBound"
                                         Orunat="server" CellPadding="5" 
                                            AutoGenerateColumns="false">
                                            <Columns>
                                                <asp:TemplateField>
                                                    <ItemTemplate>
                                                        <asp:Image Width="32px" ID="statusImage" runat="server" Height="32px"></asp:Image>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="LogId">
                                                    <ItemTemplate>
                                                        <%# DataBinder.Eval(Container.DataItem, "LogId") %>
                                        CommandArgument='<%# Container.DataItemIndex %>' runat="server" ID="btnRequest"></asp:LinkButton>--%>
                                        </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="Name">
                                                    <ItemTemplate>
                                                        <%# DataBinder.Eval(Container.DataItem, "Name")%>        </ItemTemplate>
                                                </asp:TemplateField>
                                             </Columns>
                                        </asp:GridView>
                                    </asp:Panel>
                                </div>
                            </td>
                        </tr>
                    </table>
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>