Solved

DropDown list in datagrid loses values of the row selected

Posted on 2011-02-11
10
612 Views
Last Modified: 2012-05-11
I have a drop down list in a datagrid, when the user selects a value, and the grid is rebinded I lose the value selected.

Would like to know How to keep the value of the dropdown that the user selected.
I am also using AJAX and the datagrid is inside an update panel
0
Comment
Question by:countrymeister
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 11

Accepted Solution

by:
rajvja earned 167 total points
ID: 34868847
Hi

Check whether the AutoPostBack is set. It should be false
0
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 167 total points
ID: 34868849
have you checked the Ispostback condition in Page_load before binding data to Grid?

can you share page_load code
0
 
LVL 1

Author Comment

by:countrymeister
ID: 34868876
Yes, I have checked the Postback condition and my dropdown list has AutoPostBack = false
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 11

Expert Comment

by:rajvja
ID: 34868963
Hi,

   Then, you need to check you BindGrid code.

It should be in
    If Not Page.IsPOstBak then
      'bind grid
    End if
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 166 total points
ID: 34869665
You need to save the selection before you rebind the grid.
0
 
LVL 1

Author Comment

by:countrymeister
ID: 34870030
CodeCruiser
How do  I do that? Anycode  examples will be helpful
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34870057
Do you have code setup to save gridview back to the DB?
0
 
LVL 1

Author Comment

by:countrymeister
ID: 34870167
Codecruiser, I have pasted my datagrid set up, I have an itemDatbound which binds the dropdown list with the values I get from the db.

My issue is how to save the changed values on the dropdown.
I cannot triger an OnSelectedIndex change on the dropdown since it is embedded in the grid, can I ?
<asp:DataGrid ID="dgItemSelect" runat="server" AutoGenerateColumns="false" ShowHeader="false" ShowFooter="false" 
    CellPadding="1" CellSpacing="0" CssClass="DataTable" EnableViewState="true">
    <Columns>
        <asp:TemplateColumn>                                    
            <ItemStyle CssClass="RowButton" HorizontalAlign="Center"  />
            <ItemTemplate>
                <asp:ImageButton ImageUrl="~/images/delete.png"  Height="16" Width="16" ToolTip="Remove Row" Text="X" ID="btnDeleteRow" runat="server" CommandName="DeleteCurrentRow"  />
            </ItemTemplate>
            
        </asp:TemplateColumn>
        <asp:TemplateColumn>
            <ItemStyle/>
            <ItemTemplate>
                <asp:TextBox borderstyle="None" Width="100px" ID="txtItemCode" runat="server"></asp:TextBox><asp:DropDownList Width="200px" ID="ddlSpecimens"  Visible="false" runat="server"></asp:DropDownList>
            </ItemTemplate>
            
        </asp:TemplateColumn>
        <asp:TemplateColumn>
            <ItemStyle  />
            <ItemTemplate>
                <asp:TextBox ReadOnly="true" Width="250px" BorderStyle="None" ID="txtDescription" runat="server"></asp:TextBox>
            </ItemTemplate>            
        </asp:TemplateColumn>
        <asp:TemplateColumn>
            <ItemStyle  />
            <ItemTemplate>
                <asp:DropDownList Width="120px" ID="ddlFrequency" runat="server"   AutoPostBack="false">
                 <asp:ListItem Text="" Value=""></asp:ListItem>
						  <asp:ListItem Text="MWF" Value="M-W-F"></asp:ListItem>
						  <asp:ListItem Text="MF" Value="M-F"></asp:ListItem>
						  <asp:ListItem Text="TTH" Value="T-TH"></asp:ListItem>						  
						  <asp:ListItem Text="TTHS" Value="T-TH-S"></asp:ListItem>
						  <asp:ListItem Text="Daily" Value="Daily"></asp:ListItem>
						  <asp:ListItem Text="Weekly" Value="Weekly"></asp:ListItem>
						  <asp:ListItem Text="Bi-Weekly" Value="B1-Weekly"></asp:ListItem>
						  <asp:ListItem Text="Monthly" Value="Monthly"></asp:ListItem>
						  <asp:ListItem Text="Bi-Monthly" Value="Bi-Monthly"></asp:ListItem>
						  <asp:ListItem Text="Quarterly" Value="Quarterly"></asp:ListItem>
						  <asp:ListItem Text="Yearly" Value="Yearly"></asp:ListItem>
                </asp:DropDownList>
                <asp:Label ID="lblFrequency" runat="server" Visible="false"></asp:Label>&nbsp;&nbsp;&nbsp;
            </ItemTemplate>            
        </asp:TemplateColumn>
         <asp:TemplateColumn>
            <ItemStyle  />
            <ItemTemplate>
                <asp:DropDownList Width="100px" ID="ddlDiagnosticCodes" runat="server" DataValueField="DiagnosticCode" DataTextField="DiagnosticCode"  ></asp:DropDownList>
                <asp:Label ID="lblDiagnostic" runat="server" Visible="false"></asp:Label>
            </ItemTemplate>            
        </asp:TemplateColumn>
    </Columns>     
</asp:DataGrid>

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34870187
Is the grid unbound?
0
 
LVL 1

Author Comment

by:countrymeister
ID: 34943361
The grid is bound in code behind
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question