[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

GridView and SelectedItem in DropDownList when editing

Posted on 2006-11-01
5
Medium Priority
?
4,180 Views
Last Modified: 2012-06-27
I've tried for 2 days now and searched the net with no results. (well, lots of results, but still having problems)

Grid has templated fields for Item and Edit.  The Item field is a label with initials, and the Edit field is a DropDownList (that is populated from a sql data source and works just fine).  The problem when entering edit mode, I need to have the drop down show the selected initials.  currently all i can get is the first entry in the drop down list.  Any idea of what I'm missing????

  <asp:SqlDataSource ID="DropDownSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:TaxConnectionString %>"
            SelectCommand="Proc_Tax706Logs_GetAdmins" SelectCommandType="StoredProcedure">
  </asp:SqlDataSource>
 <asp:GridView
            ID="GridView1"
            runat="server"
            AutoGenerateColumns="False"
            DataSourceID="TaxLogSelectStatement"
            DataKeyNames="ID, AdminInitials"
            AllowSorting="True"
            AllowPaging="True">
 <ItemTemplate>
      <table cellpadding="0" cellspacing="0" border="1" align="left" >
            <tr>
                 <td ><asp:Label ID="AccountNoLabel" STYLE="text-align:center; " runat="server"
                            Text='<%# Eval("AccountNumber") %>' foreColor="teal"  Font-Bold="True" Font-Size="12px"  Width=75 /></td>
                <td ><asp:Label ID="AccountNameLabel" runat="server"  Text='<%# Eval("AccountName") %>'
                             foreColor="teal" Font-Bold="True" Font-Size="12px"  Width="200" /></td>
                <td ><asp:Label ID="AdminLabel" runat="server" STYLE="text-align: center; " 
                            Text='<%# Eval("AdminInitials") %>&nbsp;' Font-Bold="false" Font-Size="12px" width="50" /></td>
            </tr>

       </table>
  </ItemTemplate>
  <EditItemTemplate>
       <table >
          <tr >
                <td ><asp:Label ID="Label5" runat="server" Text='Account Number' /></td>
                <td ><asp:textbox ID="AccountNoTextBox"  runat="server"
                           Text='<%# Bind("AccountNumber") %>'  /></td>
           </tr >
           <tr >
                 <td ><asp:Label ID="Label6" runat="server" Text='Name' /></td>
                 <td ><asp:textbox ID="AccountNameTextBox" AutoPostBack="false" Text='<%# Bind("AccountName") %>'  /></td>
          </tr>
          <tr id="AdministratorEditRow" >
               <td ><asp:Label ID="Label7" runat="server" style=" text-align:right;" Text='Administrator' /></td>
               <td ><asp:DropDownList ID="OfficerDropDownListUpdate" AutoPostBack="false" runat="server" DataSourceID="DropDownSqlDataSource"
                          DataTextField="AdminInitials" SelectedText='<%# Eval("AdminInitials") %>' DataValueField="AdminID" /></td>
                            </tr>
              </tr>
      </table>
  </EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

thanks for taking a look

0
Comment
Question by:PTBNA
[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
  • 3
5 Comments
 
LVL 6

Expert Comment

by:LeeHenry
ID: 17852169
In your code behind, you should set the dropdownlist selected value when in edit mode

OfficerDropDownListUpdate.SelectedIndex = yourSelectedIndex;

0
 

Author Comment

by:PTBNA
ID: 17852710
Ok, but which of the events should I use,
row databound,
row editing
row created,

I've worked with all of them, but am missing something to put it all together.

Do you have some sample code??

Plus, I know you can't just set the OfficerDropDownListUpdate.SelectedIndex, it has to be found in the Gridview control list.
0
 

Author Comment

by:PTBNA
ID: 17853616
Well, in case anyone's looking, I did a test, putting a label just below the Drop down list, and "Eval'd" the AdminInitials.  

And as expected they are there.  So, why with the Dropdown bound to a sql data source, and the Selected text set to the item in the grid, don't we get the Dropdownlist selected Item set???

0
 

Author Comment

by:PTBNA
ID: 17853667
Found the solution.

Cannot set the SelectedText value in the drop down.  Must use the SelectedValue.  Changing the statement, now the dropdownlist shows the selected item when we are in edit mode.

thanks for the help
0
 

Accepted Solution

by:
RomMod earned 0 total points
ID: 17854794
Question closed - 500 points refunded.

Best regards,
RomMod
Experts Exchange
Community Support Moderator
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

650 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