Solved

DropDown list in datagrid loses values of the row selected

Posted on 2011-02-11
10
611 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

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.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

777 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