Solved

DropDown list in datagrid loses values of the row selected

Posted on 2011-02-11
10
615 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

695 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