Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Manage a GridView's HyperLinkField column's width? [modified]

Manage a GridView's HyperLinkField column's width? [modified]

Scheduled Pinned Locked Moved ASP.NET
htmlsysadminhelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dr_X
    wrote on last edited by
    #1

    Scenario: I was using Template columns with ImageButtons with no problem controlling the columns' width. However template columns are not allowed when 'EnableSortingAndPagingCallbacks="True"'. Original html code:

    <asp:TemplateField ItemStyle-Width="22px">
    <ItemTemplate>
    <asp:ImageButton ID="imbView" runat="server" ImageUrl="~/Images/ViewSearch.gif" />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField ItemStyle-Width="22px">
    <ItemTemplate>
    <asp:ImageButton ID="imgEdit" runat="server" ImageUrl="~/Images/Edit.gif" />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField ItemStyle-Width="22px">
    <ItemTemplate>
    <asp:ImageButton ID="imgDelete" runat="server" ImageUrl="~/Images/Delete.gif" />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField ItemStyle-Width="22px">
    <ItemTemplate>
    <asp:ImageButton ID="imgPrint" runat="server" ImageUrl="~/Images/Print.gif" />
    </ItemTemplate>
    </asp:TemplateField>

    So I replaced the template columns with HyperLinkField. Then in the onRowDataBound event in the code-behind, I set the images to the respective links.

    </asp:HyperLinkField DataNavigateUrlFormatString="~/Invoices/Invoice.aspx?id={0}&Readonly" DataNavigateUrlFields="InvoiceID" ItemStyle-Width="20px" />
    </asp:HyperLinkField DataNavigateUrlFormatString="~/Invoices/Invoice.aspx?id={0}&Edit" DataNavigateUrlFields="InvoiceID" />
    </asp:HyperLinkField DataNavigateUrlFormatString="~/Reports/Reports.aspx?DeleteFromSomeWhere" DataNavigateUrlFields="InvoiceID" />
    </asp:HyperLinkField DataNavigateUrlFormatString="~/Reports/Reports.aspx?id={0}" DataNavigateUrlFields="InvoiceID" />

    public void dgData\_onRowDataBound(Object src, GridViewRowEventArgs e)
    {
      if (e.Row.RowType == DataControlRowType.DataRow)
      {
        DataRowView row = (DataRowView)e.Row.DataItem;
        HyperLink link = (HyperLink)e.Row.Cells\[0\].Controls\[0\];
        if (!(link == null))
        {
          link.ImageUrl = "~/Images/ViewSearch.gif";
          link.ToolTip = "Print";
        }
        link = (HyperLink)e.Row.Cells\[1\].Controls\[0\];
        if (!(link == null))
        {
          link.ImageUrl = "~/Images/Edit.gif";
          link.ToolTip = "Print";
        }
        link = (HyperLink)e.Row.Cells\[2\].Controls\[0\];
        if (!(link == null))
        {
          link.ImageUrl = "~/Images/Delete.gif";
          link.ToolTip = "Delete Invoice
    
    M 1 Reply Last reply
    0
    • D Dr_X

      Scenario: I was using Template columns with ImageButtons with no problem controlling the columns' width. However template columns are not allowed when 'EnableSortingAndPagingCallbacks="True"'. Original html code:

      <asp:TemplateField ItemStyle-Width="22px">
      <ItemTemplate>
      <asp:ImageButton ID="imbView" runat="server" ImageUrl="~/Images/ViewSearch.gif" />
      </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField ItemStyle-Width="22px">
      <ItemTemplate>
      <asp:ImageButton ID="imgEdit" runat="server" ImageUrl="~/Images/Edit.gif" />
      </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField ItemStyle-Width="22px">
      <ItemTemplate>
      <asp:ImageButton ID="imgDelete" runat="server" ImageUrl="~/Images/Delete.gif" />
      </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField ItemStyle-Width="22px">
      <ItemTemplate>
      <asp:ImageButton ID="imgPrint" runat="server" ImageUrl="~/Images/Print.gif" />
      </ItemTemplate>
      </asp:TemplateField>

      So I replaced the template columns with HyperLinkField. Then in the onRowDataBound event in the code-behind, I set the images to the respective links.

      </asp:HyperLinkField DataNavigateUrlFormatString="~/Invoices/Invoice.aspx?id={0}&Readonly" DataNavigateUrlFields="InvoiceID" ItemStyle-Width="20px" />
      </asp:HyperLinkField DataNavigateUrlFormatString="~/Invoices/Invoice.aspx?id={0}&Edit" DataNavigateUrlFields="InvoiceID" />
      </asp:HyperLinkField DataNavigateUrlFormatString="~/Reports/Reports.aspx?DeleteFromSomeWhere" DataNavigateUrlFields="InvoiceID" />
      </asp:HyperLinkField DataNavigateUrlFormatString="~/Reports/Reports.aspx?id={0}" DataNavigateUrlFields="InvoiceID" />

      public void dgData\_onRowDataBound(Object src, GridViewRowEventArgs e)
      {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
          DataRowView row = (DataRowView)e.Row.DataItem;
          HyperLink link = (HyperLink)e.Row.Cells\[0\].Controls\[0\];
          if (!(link == null))
          {
            link.ImageUrl = "~/Images/ViewSearch.gif";
            link.ToolTip = "Print";
          }
          link = (HyperLink)e.Row.Cells\[1\].Controls\[0\];
          if (!(link == null))
          {
            link.ImageUrl = "~/Images/Edit.gif";
            link.ToolTip = "Print";
          }
          link = (HyperLink)e.Row.Cells\[2\].Controls\[0\];
          if (!(link == null))
          {
            link.ImageUrl = "~/Images/Delete.gif";
            link.ToolTip = "Delete Invoice
      
      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi Michael, There are a couple of ways which you can try: + Use Atlas with your GridView control, you can keep using the TemplateField and simply place the GridView control inside the UpdatePanel to support client callback with paging and sorting. + Use the ButtonField with ButtonType="Image":

      <asp:ButtonField ItemStyle-Width="22px" ButtonType="Image" ImageUrl="..." />

      + Use the BoundField with adding the ImageButton to the column in the RowDataBound event handler:

      <asp:BoundField ItemStyle-Width="22px" />

      D 1 Reply Last reply
      0
      • M minhpc_bk

        Hi Michael, There are a couple of ways which you can try: + Use Atlas with your GridView control, you can keep using the TemplateField and simply place the GridView control inside the UpdatePanel to support client callback with paging and sorting. + Use the ButtonField with ButtonType="Image":

        <asp:ButtonField ItemStyle-Width="22px" ButtonType="Image" ImageUrl="..." />

        + Use the BoundField with adding the ImageButton to the column in the RowDataBound event handler:

        <asp:BoundField ItemStyle-Width="22px" />

        D Offline
        D Offline
        Dr_X
        wrote on last edited by
        #3

        I ended up going with the Atlas:UpdatePanel. Thanks! I firmly believe that any man's finest hour, the greatest fulfillment of all that he holds dear, is that moment when he has worked his heart out in a good cause and lies exhausted on the field of battle - victorious. Vince Lombardi (1913-1970)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups