Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Everyone, I have stumbled into a strange issue. I have a GridView with sevEral Columns, two of those Columns have dropdowns. One of the dropdowns works as expected, the other shows the selected value for a second and then reverts to something else.

What makes it strange is that it works fine for 2 out of the 10 values listed in the dropdown.
In the Column template I included a textbox together with the dropdown, but I don't think this will be the issue. I added a break point to the SelectedIndexChange, and by the time it hits the SelectedIndexChange the value has already being changed.

This is a portion of the markup:
ASP.NET
<asp:TemplateField FooterText="cCommentDesc" HeaderText="cCommentDesc"  SortExpression="cCommentDesc">
                    <ItemTemplate>
                        <asp:TextBox ID="txtComment" runat="server" Width="200px"
                            Text = '<%# Eval("cComment") %>'
                            ReadOnly="True">
                        </asp:TextBox>

                     <asp:DropDownList
                        ID="cboComment"
                        runat="server"
                        DataSourceID = "SQLCommentsDataSource"
                        DataTextField="cCommentDesc"
                        DataValueField="cRtnVal"
                        OnSelectedIndexChanged="cboComment_SelectedIndexChanged"
                        AutoPostBack="True"
                        Width="100px"
                        style="margin-left: 0px;">
                     </asp:DropDownList>

                    </ItemTemplate>

</asp:TemplateField>



SQLCommentsDataSource is defined as:

HTML
SELECT TOP 1 NULL AS cCommentDesc, NULL AS cRtnVal, 0 As nOrder
                           FROM DropDownsValues 
                           UNION
                           SELECT cValue AS cCommentDesc, cRtnVal, nOrder
                           FROM DropDownsValues
                           WHERE cKeyName = 'ServerComments'
                           ORDER BY nOrder 


Thank you in advance.

Luis
Posted

1 solution

I found the root of the problem, but don't know exactly how to proceed. In the select statement above the cRtnVal column only contains two values "Yes" or "No". out of the ten values three are
Yes" and the rest are "No". When the DataValueField has duplicates the first value in the list is selected every time. I can force the values to be distinct by appending a sequential number and then use LEFT(cRtnVal,...) , but why?



Any suggestions?

Thank you,
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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