Remove or delete duplicate values in gridview

dotnet_rookie

New member
Joined
Jul 20, 2009
Messages
2
Programming Experience
Beginner
Hi

I am binding data to 2 checkboxes in a gridview using item template. I am trying to remove the duplication of the 1st checkboxes. The 2nd checkbox displays the subcategory of 1st checkbox. So I need to have only one checkbox for category for all the subcategories displayed and trying to remove the duplicate values. I am unable to do it with the code below:


VB.NET:
<asp:GridView ID="GridView1" runat="server" AllowPaging="False" AllowSorting="True"
AutoGenerateColumns="False" DataSourceID="CatSource" Width="496px" CellPadding="4"
OnRowDataBound="GridView1_RowDataBound" ForeColor="#333333" GridLines="Vertical">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<input type="checkbox" id="chkAll" name="chkAll" onclick="check(this)" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" Text='<%# Eval("M_CATPAGES_CAT") %>' />
<asp:Label ID="lblchkd" runat="server" Text='<%#Eval("M_PAGES_ID_PK") %>' Visible="true"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkSubcat" runat="server" Text='<%# Eval("M_PAGES_PAGES") %>' />
</ItemTemplate>

</asp:TemplateField>
</Columns>
</asp:GridView>


<asp:SqlDataSource ID="CatSource" runat="server" DataSourceMode="DataSet" ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
SelectCommand="Select a.M_PAGES_ID_PK,a.M_PAGES_PAGES,b.M_CATPAGES_CAT from mast_pages_tbl as a inner join mast_catpages_tbl as b on a.M_PAGES_CATID = b.M_CATPAGES_ID"
ProviderName="System.Data.Odbc"></asp:SqlDataSource>


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

GenerateUniqueData(0)

End Sub


Private Sub GenerateUniqueData(ByVal cellno As Integer)


Dim initialnamevalue As String = GridView1.Rows(0).Cells(cellno).Text



For i As Integer = 0 To GridView1.Rows.Count - 1

If GridView1.Rows(i).Cells(cellno).Text = initialnamevalue Then
GridView1.Rows(i).Cells(cellno).Text = String.Empty
Else
initialnamevalue = GridView1.Rows(i).Cells(cellno).Text
End If
Next
End Sub
 
Back
Top