0

I have a Gridview that is correctly getting data from a database. I want to add an image in each row that when clicked, will link to another page and that link will have a parameter passed with it. If I was using a HyperLinkField, I would use the DataNavigateUrlFormatString attribut but it does not work when using the ButtonField. Am I missing something silly here? My code is below. Thank you.

            <asp:Panel runat="server" ID="pnlresults" Visible="false">
                <asp:SqlDataSource runat="server" ID="requestedDataSource"
                    CancelSelectOnNullParameter="false"
                    ConnectionString="<%$ ConnectionStrings:UnitySQLServerConnectionString %>"
                    SelectCommand="SELECT PriceListID, PriceListCode, PriceListName, isActive, StartDate, EndDate FROM [SQLQA].[dbo].[Price_Header]">
                </asp:SqlDataSource>
                <asp:GridView runat="server"
                    AllowSorting="true"
                    AutoGenerateColumns="false"
                    DataSourceID="requestedDataSource"
                    CssClass="searchOutput"
                    HeaderStyle-HorizontalAlign="Left" 
                    RowStyle-HorizontalAlign="Left"
                    AlternatingRowStyle-HorizontalAlign="Left">
                    <Columns>
                        <asp:BoundField DataField="PriceListCode" HeaderText="Code" />
                        <asp:BoundField DataField="PriceListName" HeaderText="Name" />
                        <asp:BoundField DataField="isActive" HeaderText="Active" />
                        <asp:BoundField DataField="StartDate" HeaderText="Start Date" />
                        <asp:BoundField DataField="EndDate" HeaderText="End Date" />
                        <asp:ButtonField HeaderText="Copy" ImageUrl="../../Images/plus.gif" ButtonType="Image" CommandName="" />
                    <asp:HyperLinkField DataNavigateUrlFields="PriceListID" HeaderText="Copy"
                            DataNavigateUrlFormatString="~/?Order_No={0}"
                            Text="Copy" />
                    </Columns>
                </asp:GridView>
            </asp:Panel>
4

1 回答 1

1

ButtonField 没有 DataNavigateUrlFormatString 属性。所以不,它不会工作。

如果要向超链接添加图像,可以这样做:

           .MyStyle {
                background-image: url('Images/Test.bmp');
                background-repeat: no-repeat;
                background-position: center center;
                width:100px;
                padding-left:50px;
                padding-right:50px;
            }

<asp:HyperLinkField ControlStyle-CssClass="MyStyle" DataNavigateUrlFields="ImageUrl" HeaderText="Test"  />
于 2014-11-10T18:43:03.373 回答