Pergunta

I have a gridview with BoundField columns and I would like to insert a new row specifically for this BoundField. Is this something that is possible to do?

The code is as follows:

                 <asp:GridView ID="grdAgreements" runat="server" AutoGenerateColumns="false" Width="100%"
        AllowSorting="false" AlternatingRowStyle-BackColor="White" 
        HeaderStyle-BackColor="White" HeaderStyle-ForeColor="GrayText" 
        Font-Names="Arial" Font-Size="11" DataKeyNames="AgreementId" OnRowCreated="grdAgreements_RowCreated" >
        <rowstyle height="24" />

    <Columns>
        <asp:BoundField HeaderText="Agreement Number" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="AgreementNumber" SortExpression="AgreementNumber" ItemStyle-Width="110" ItemStyle-Font-Names="Arial" />
        <asp:BoundField HeaderText="Description" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="Description" SortExpression="Description" ItemStyle-Width="100" ItemStyle-Font-Names="Arial" />
        <asp:BoundField HeaderText="Start Date" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="StartDate" SortExpression="StartDate" ItemStyle-Width="125" ItemStyle-Font-Names="Arial" />
        <asp:BoundField HeaderText="End Date" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="EndDate" SortExpression="EndDate" ItemStyle-Width="200" ItemStyle-Font-Names="Arial" />

        <asp:BoundField HeaderText="Site Number" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="SiteNumber" SortExpression="SiteNumber" ItemStyle-Width="200" ItemStyle-Font-Names="Arial" />

    </Columns>

    <EmptyDataTemplate>
        There are no agreements to display.
    </EmptyDataTemplate>
</asp:GridView>

What I would like to happen is that instead of the BoundField I would like to have the SiteNumber databound to a new row that I could stick in a div or panel. How would I go about doing this?

Foi útil?

Solução 2

As per the usual time constraints I didn't go through and figure out the best way to use the Listview for my needs but I did figure a way to get the layout that I was looking for using styled tables within a TemplateField and ItemTemplate. The following code is what I came up with and hopefully this will help someone else looking for a similar solution. If time constraints are not on your plate I highly suggest looking further into the Listview control. P.S. The css I used was a huge PITA to get everything styled perfect but it was definitely worth it IMHO. And this was all within a GridView BTW

<asp:TemplateField>
      <ItemTemplate>
      <div class="EquipmentTable1" >
            <table >
                <tr>
                    <td>
                        Customer Equipment
                    </td>
                    <td>
                        Contract
                    </td>
                    <td >
                        Contract Number
                    </td>

                    <td>
                        Modality
                    </td>
                </tr>
                <tr>
                    <td>
                    <%--TODO link this to the customer equipment record pulled from the services web portal guide part 1 document--%>
                      <a href="../Agreements/AgreementList.aspx?CustomerEquipmentID=<%# Eval("CustomerEquipmentID") %>"><%# Eval("CustomerEquipmentID") %>  </a> 
                    </td>
                    <td >
                    <%--Link to the agreement page and
                    pass in the agreement id as a query string to do a lookup of the agreement--%>
                    <a href="../Agreements/AgreementView.aspx?AgreementID=<%# Eval("AgreementID") %>"><%# Eval("AgreementID") %></a>
                    </td>
                    <td>
                        <%# Eval("AgreementLineID") %>
                    </td>

                     <td>
                        <%# Eval("ModalityID") %>
                    </td>
                </tr>
            </table>
        </div>
  <div class="EquipmentTable2" >
            <table >
                <tr>
                    <td>
                       Product
                    </td>
                    <td >
                        Model Number
                    </td>
                    <td>
                        Room Number
                    </td>
                    <td>
                        Date Installed
                    </td>
                </tr>
                <tr>
                    <td >
                        <%# Eval("Product") %>
                    </td>
                    <td>
                       <%# Eval("ModelNumber") %>
                    </td>
                     <td>
                       <%# Eval("RoomNumber") %>
                    </td>
                    <td>
                        <%# Eval("DateInstalled") %>
                    </td>
                </tr>
            </table>
        </div>
      </ItemTemplate>
      </asp:TemplateField>

Outras dicas

Let me know if I am not understanding it right but if you want to customize the layout of the field you can use TemplateField instead of BoundField

<asp:TemplateField HeaderText="SiteNumber" SortExpression="SiteNumber">
    <ItemTemplate>
        <asp:Label ID="Label1" runat="server" Text='<%# Bind("SiteNumber") %>'></asp:Label>
    </ItemTemplate>
</asp:TemplateField>

But if you are thinking of moving that particular column in to a new row then you will have to look into other databound controls like ListView or Repeater as GV markup isn't that customizable.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top