Click here to Skip to main content
15,909,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to prevent duplicate entry from combobox in gridview itemtemplate which is first column of gridview? how i can check already selection has done from combobobox?

ASP.NET
<asp:TemplateField HeaderText="Item" ItemStyle-Height ="10px">
                                                                    <ItemTemplate>
                                                                        <asp:ComboBox ID="cbaccount" runat="server" DataSourceID="SqlDataSource5" DataTextField="itemname" AutoPostBack="true" onkeyup=" UnHighlight(this)"
                                                                            DataValueField="itemid" Width="180px" AutoCompleteMode="SuggestAppend" CssClass="WindowsStyle cb" DropDownStyle="DropDownList" AppendDataBoundItems="True" OnSelectedIndexChanged="cbaccount_SelectedIndexChanged" >
                                                                          <asp:ListItem Selected="True" Text=""></asp:ListItem>
                                                                        </asp:ComboBox>
                                                                         <asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionASPX %>"
                                                                               SelectCommand="SELECT  [itemname],[itemid] FROM [itemadd]  ORDER BY [itemname]">

                                                                         </asp:SqlDataSource>

                                                                    </ItemTemplate>
                                                                        <HeaderStyle HorizontalAlign="Left" CssClass="HeaderStyle1"  />
                                                                            <ItemStyle Width="180px"  />

                                                            </asp:TemplateField>
Posted
Updated 13-Aug-12 23:47pm
v2

1 solution

Change your SELECT as :

SelectCommand="SELECT DISTINCT [itemname],[itemid] FROM [itemadd] ORDER BY [itemname]">
 
Share this answer
 
Comments
veenusethi 16-Aug-12 4:42am    
No sir, in combobox itemname is a unique. i dont want any duplicasy in dynamic gridview ? if user select item name for first time i do not want user select that item again in gridview?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900