I have a gridview connected to a SQLDataSource (sds1 )and in each row, theres 2 combobox that are also connected to a SQLDataSource (Both combobox share the same datasource : sds2).
I would like to prevent the combobox to have the same value offered in each row. If user edit a row and he chose value ABC in combo1, I would like to have that value ABC removed from combo2.
All my sqldatasource are connected to a storedproc on sql server.
I know it could be possible to block the update in codebehind (in updating event or itemindexchange) by verifying the value of both combobox but I wanted to know if it was possible to remove that value from the combobox.
when you click remove at that time you just bind both the combobox again....
Dont forgot to mark as answer.....
Hummm, I have not choosen the right word I guess, when I say removed from combobox2, I meant to have that value unavailable (but the value still remain in database) to the user.
So DDLintPlayerGoal and DDLintPlayerAssist can't be the same value. I want, if possible, to block the possibility for the user to choose the same player in each combobox. I know it could be possible in codeBehind, but I would prefer, if possible, to hide
in combox2 the value already selected in combo1
just add one extra boolean field to database having Available 'A' or Not 'N' when you want to remove any value for any user then update database and mark as 'N' and if you want to show him mark as 'A'.......
And when you bind combo write,
select <something> from <table> where Availabe = 'A';
marric01
Member
17 Points
34 Posts
2 combox on same row, same datasource, block choosing same values
Apr 30, 2012 01:37 PM|LINK
Hi,
I have a gridview connected to a SQLDataSource (sds1 )and in each row, theres 2 combobox that are also connected to a SQLDataSource (Both combobox share the same datasource : sds2).
I would like to prevent the combobox to have the same value offered in each row. If user edit a row and he chose value ABC in combo1, I would like to have that value ABC removed from combo2.
All my sqldatasource are connected to a storedproc on sql server.
I know it could be possible to block the update in codebehind (in updating event or itemindexchange) by verifying the value of both combobox but I wanted to know if it was possible to remove that value from the combobox.
Thanks
keval.trived...
Member
159 Points
87 Posts
Re: 2 combox on same row, same datasource, block choosing same values
Apr 30, 2012 01:44 PM|LINK
Hi marric01,
when you click remove at that time you just bind both the combobox again....
Dont forgot to mark as answer.....
marric01
Member
17 Points
34 Posts
Re: 2 combox on same row, same datasource, block choosing same values
Apr 30, 2012 01:51 PM|LINK
Hummm, I have not choosen the right word I guess, when I say removed from combobox2, I meant to have that value unavailable (but the value still remain in database) to the user.
keval.trived...
Member
159 Points
87 Posts
Re: 2 combox on same row, same datasource, block choosing same values
Apr 30, 2012 01:53 PM|LINK
share your code plzz.....
marric01
Member
17 Points
34 Posts
Re: 2 combox on same row, same datasource, block choosing same values
Apr 30, 2012 02:30 PM|LINK
<asp:GridView ID="gvScoreSheetProductionVisiteur" runat="server" Width="95%" AutoGenerateColumns="False" DataSourceID="sdsScoreSheetProductionVisiteur" ShowFooter="True" DataKeyNames="intIDSSJoueurBut" OnRowCommand="gvScoreSheetProductionVisiteur_RowCommand" ShowHeaderWhenEmpty="True" AllowSorting="True"> <AlternatingRowStyle CssClass="AltRowStyle" /> <Columns> <asp:TemplateField HeaderText="But" SortExpression="strNomCompletBut"> <EditItemTemplate> <ajaxToolkit:ComboBox ID="DDLintPlayerGoal" runat="server" DataSourceID="sdsLineUpJoueurVisiteur" DataTextField="strNomComplet" DataValueField="intIDSSJoueur" SelectedValue='<%# Bind("FKintIDSSJoueurBut") %>' AutoCompleteMode="SuggestAppend" MaxLength="0" Style="display: inline;"> </ajaxToolkit:ComboBox> </EditItemTemplate> <ItemTemplate> .... </ItemTemplate> <FooterTemplate> ..... </FooterTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Passe" SortExpression="strNomCompletPasse"> <EditItemTemplate> <ajaxToolkit:ComboBox ID="DDLintPlayerAssist" runat="server" DataSourceID="sdsLineUpJoueurVisiteur" DataTextField="strNomComplet" DataValueField="intIDSSJoueur" SelectedValue='<%# Bind("FKintIDSSJoueurPasse") %>' AutoCompleteMode="SuggestAppend" MaxLength="0" Style="display: inline;" AppendDataBoundItems="true"> <asp:ListItem Value="" Selected="True">Unassisted</asp:ListItem> </ajaxToolkit:ComboBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label6" runat="server" Text='<%# Bind("strNomCompletPasse") %>'></asp:Label> </ItemTemplate> <FooterTemplate> .... </FooterTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Période" SortExpression="strPeriodeBut"> ..... </asp:TemplateField> <asp:TemplateField HeaderText="Temps du but" SortExpression="strTempBut"> ..... </asp:TemplateField> <asp:TemplateField HeaderText="Type but" SortExpression="strTypeBut"> ...... </asp:TemplateField> <asp:TemplateField HeaderText="Actions"> ..... </asp:TemplateField> </Columns> <EditRowStyle CssClass="EditRowStyle" /> <EmptyDataTemplate> ...... </EmptyDataTemplate> <FooterStyle CssClass="RowStyle" /> <HeaderStyle CssClass="HeaderStyle" /> <PagerStyle CssClass="PagerStyle" /> <RowStyle CssClass="RowStyle" /> <SelectedRowStyle CssClass="SelectedRowStyle" /> </asp:GridView>So DDLintPlayerGoal and DDLintPlayerAssist can't be the same value. I want, if possible, to block the possibility for the user to choose the same player in each combobox. I know it could be possible in codeBehind, but I would prefer, if possible, to hide in combox2 the value already selected in combo1
thanks
keval.trived...
Member
159 Points
87 Posts
Re: 2 combox on same row, same datasource, block choosing same values
May 01, 2012 06:18 AM|LINK
just add one extra boolean field to database having Available 'A' or Not 'N' when you want to remove any value for any user then update database and mark as 'N' and if you want to show him mark as 'A'.......
And when you bind combo write,
select <something> from <table> where Availabe = 'A';
keval.trived...
Member
159 Points
87 Posts
Re: 2 combox on same row, same datasource, block choosing same values
May 01, 2012 09:50 AM|LINK
And if you dont want to change in database then,
try { DropDownList2.Items.Remove(DropDownList1.SelectedItem); DropDownList1.Items.Remove(DropDownList1.SelectedItem); } catch (Exception e) { }dont forgot to write,
when you bind your data