Solved

DropDown list in datagrid loses values of the row selected

Posted on 2011-02-11
10
610 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
Comment Utility
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
Comment Utility
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
Comment Utility
Yes, I have checked the Postback condition and my dropdown list has AutoPostBack = false
0
 
LVL 11

Expert Comment

by:rajvja
Comment Utility
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
Comment Utility
You need to save the selection before you rebind the grid.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 1

Author Comment

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

Expert Comment

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

Author Comment

by:countrymeister
Comment Utility
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
Comment Utility
Is the grid unbound?
0
 
LVL 1

Author Comment

by:countrymeister
Comment Utility
The grid is bound in code behind
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
advertisement module in core php 4 76
How do I get the id from URL? 19 45
Hovering effect 9 28
getting id from database 5 23
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now