Avatar of PNKJ
PNKJ

asked on 

Grid view Item style

I want to show all products related to same group id which is a field in database but not displayed on grid in one row in grid view. Is it possible to do that programmatically. I want to show both the rows in jyst one row and the records of both rows have the same group id. The next group will be in the next row and so on.

for eg
ABC                  Description              Unit
            DEF       Description             Unit
ASP.NET

Avatar of undefined
Last Comment
PNKJ
Avatar of naspinski
naspinski
Flag of United States of America image

Gridview requires one row per item.  This is quite possible, but not with gridview.

BUT, you could make it _look_ like that is whats happening by using a trick that alternates the background depending on what the groupID is.  That way it would look lihe they are in the same row, but not actually be...?
Avatar of PNKJ
PNKJ

ASKER

Can you please show an example
ASKER CERTIFIED SOLUTION
Avatar of naspinski
naspinski
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of PNKJ
PNKJ

ASKER

Hi

I am not getting it to work. Please canyou take a look at my grid code that i have. These prodcuts are grouped together by groupId from database. In my attached file all these three products are grouped together.


                               
                               
                               
                               
                               
                                   
                                   
                                       
                                           
                                       
                                       
                                   
                                   
                                       
                                           
                                       
                                       
                                   
                                   
                                   
                                   
                           
                           
grid.bmp
Avatar of naspinski
naspinski
Flag of United States of America image

Looks like you never even call the function anywhere?
Also, for this to work, all of your fields have to be templateFields and have s placed in them like the example I gave
Avatar of PNKJ
PNKJ

ASKER

Sorry I only posted the code of aspx page In my code behind I am callign this function
Protected Sub ddlMonthYearImport_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlMonthYearImport.SelectedIndexChanged
        lobj_CodeChanges = New-Business -ayer.CodeChangeManager
        lobj_Dataset = lobj_CodeChanges.CodeChangesDataGet("M", ddlMonthYearImport.SelectedValue.ToString, txtXCommodityCodesearch.Text, CType(rblMcommoditysearchtype.SelectedValue.ToString, Boolean))
        gvImportsCodeChanges.DataSource = New DataView(lobj_Dataset.Tables(0))
        gvImportsCodeChanges.DataBind()
          End Sub
Avatar of naspinski
naspinski
Flag of United States of America image

still dont see you trying to call the function or using the divs in any way.  Maybe you should look at my example again.
Avatar of PNKJ
PNKJ

ASKER

May be I am not getting you do I have to add grid view in div tag?
Avatar of PNKJ
PNKJ

ASKER

DO I ahve to add   around each databound field?
Avatar of PNKJ
PNKJ

ASKER

Sorry but I am using vb.net code not C#
Avatar of PNKJ
PNKJ

ASKER

ok I changed the code to vb.net and declared the global variables but It get error at this line
 Return IIf(switcher, "blue", "navy") option strict on disallows implicit converstion from object to string

'needs to be set at a global level
    Public Function getColor(ByVal o As Object) As String
        If Not o.ToString().Equals(lastValue) Then
            switcher = Not switcher
        End If
        lastValue = o.ToString()
        Return IIf(switcher, "blue", "navy")
        'colors to switch
    End Function
Avatar of PNKJ
PNKJ

ASKER

Here is how I amusingt his code. when I debug the switcher works but it takes only one style sheet not the one if switcher changes. I canot add bound fields in itemtemplate it has to be either hyperlink or button control
Declared these variables in my code behind page
 Private switcher As Boolean = False
    Private lastValue As String = String.Empty

  <asp:TemplateField HeaderText="Old Code">
                                    <ItemTemplate>
                                        <div style="background: <%# getColor(Eval("batchID"))%>">
                                            <asp:Button ID="cmoldCode" runat="server" Text='<%# Bind("obsolete_commodity_code")%>'
                                                CssClass="stdGridButtonCenter" CausesValidation="FALSE" CommandName="OldCommoditySelect" />
                                        </div>
                                    </ItemTemplate>
                                    <HeaderStyle Wrap="False" CssClass="stdGridLeft" />
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="New Code">
                                    <ItemTemplate>
                                        <div style="background: <%# getColor(Eval("batchID"))%>">
                                            <asp:Button ID="cmnewCode" runat="server" Text='<%# Bind("new_commodity_code")%>'
                                                CssClass="stdGridButtonCenter" CausesValidation="FALSE" CommandName="NewCommoditySelect" />
                                        </div>
                                    </ItemTemplate>
                                    <HeaderStyle Wrap="False" CssClass="stdGridLeft" />
                                </asp:TemplateField>
                                <asp:BoundField HeaderText="Name" DataField="short_description" HeaderStyle-HorizontalAlign="Right" />
                                <asp:BoundField HeaderText="Ag?" DataField="agricultural_flag" />
                                <asp:BoundField HeaderText="Census1" DataField="unit_of_measure_1" ItemStyle-HorizontalAlign="Right"
                                    HeaderStyle-HorizontalAlign="Right" />
                                <asp:BoundField HeaderText="Census2" DataField="unit_of_measure_2" ItemStyle-HorizontalAlign="Right"
                                    HeaderStyle-HorizontalAlign="Right" />
                                <asp:BoundField HeaderText="Fas Conv" DataField="converted_unit_of_measure" ItemStyle-HorizontalAlign="Right"
                                    HeaderStyle-HorizontalAlign="Right" />
                                <asp:BoundField HeaderText="Fas NonConv" DataField="non_converted_unit_of_measure"
                                    ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" />
                                <asp:BoundField HeaderText="Description" DataField="long_description" HeaderStyle-HorizontalAlign="Right" />
                                <asp:BoundField HeaderText="Type" DataField="import_export_flag" ItemStyle-HorizontalAlign="Right"
                                    HeaderStyle-HorizontalAlign="Right" />
                            </Columns>
                        </asp:GridView>


 Public Function getColor(ByVal o As Object) As String
        If Not o.ToString().Equals(lastValue) Then
            switcher = Not switcher
        End If
        lastValue = o.ToString()
        If switcher = True Then 'colors to switch
            gvExportcodeChanges.RowStyle.CssClass = "stdGridAltRow"
        Else
            gvExportcodeChanges.RowStyle.CssClass = "stdGridItem"
            'RowStyle(CssClass = "stdGridItem")
        End If
       

    End Function
Avatar of PNKJ
PNKJ

ASKER

naspinski:

I tried this function but it works partially. First of all I cannot have all bound fields in </asp:TemplateField>.
and it is only taking one class. Probably coz I haven't added the function to all my fields. May be my code is not correct. What is happening is that my entire grid takes one style sheet only wheras i want alternate groups. Please take a look at the code pasted above  
If switcher = True Then 'colors to switch
            gvExportcodeChanges.RowStyle.CssClass = "stdGridAltRow"
        Else
            gvExportcodeChanges.RowStyle.CssClass = "stdGridItem"
            'RowStyle(CssClass = "stdGridItem")
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo