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>
joerdie
  • 379
  • 1
  • 6
  • 18

1 Answers1

1

The ButtonField doesn't have a DataNavigateUrlFormatString attribute. So no, it will not work.

If you want to add an image to the hyperlink, you can do it something like this:

           .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"  />
Steve Wellens
  • 20,506
  • 2
  • 28
  • 69
  • This works, except I cannot seem to get the DataTextField text to not show. any fiddling with it and the background image will go away. – joerdie Nov 10 '14 at 19:04
  • I modified my answer to have the bare minimum (no text) and it seems to work. – Steve Wellens Nov 10 '14 at 19:25
  • Okay. No matter how much I fiddle with this, the text shows up upon hover or the image has no mass so it disappears. There has to be a way to just tie the image to a url that I can format right? – joerdie Nov 12 '14 at 16:50