Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

DropDownlist control

Posted on 2006-07-11
3
Medium Priority
?
219 Views
Last Modified: 2010-04-16
Morning guys,

I am carrying out an update on a dropdown control with works perfectly.
So when a user selects an item from the dropdown it updates in the
database. But on pageload I what the new selected item to be visible
and not default item on the dropdown.

EXAMPLE.
1)original item on the dropdown is A,
2)the new selected item is B
3)but on pageload it defaults to A, BUT SHOULD BE B.

thanks guys


public void dgCompensation_ItemDataBound(Object Sender, DataGridItemEventArgs e)
            {
   
                  if (e.Item.ItemType == ListItemType.EditItem)
                  {
        
                      DataRowView objDataRowView = (DataRowView)e.Item.DataItem;
                      string currentDeduction = (string)objDataRowView[2].ToString();
                          DropDownList ctlDropDownList = (DropDownList)e.Item.FindControl("DeductDropDownList");
            
                        if (ctlDropDownList != null)
                        {
                              ctlDropDownList.Items.Add("Y");
                              ctlDropDownList.Items.Add("N");
                              ctlDropDownList.Items.Add("E");
                        }
                        ctlDropDownList.SelectedIndex = ctlDropDownList.Items.IndexOf(ctlDropDownList.Items.FindByText(currentDeduction));
                  }
   
            }
      
0
Comment
Question by:SirReadAlot
[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
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 17080201
This works for 2.0, not sure about 1.1:

            string s = "N";

            comboBox1.Items.Add("Y");
            comboBox1.Items.Add("N");
            comboBox1.Items.Add("E");

            int i = comboBox1.FindString(s);
            comboBox1.SelectedIndex = i;
0
 

Author Comment

by:SirReadAlot
ID: 17080220
will try
0
 

Author Comment

by:SirReadAlot
ID: 17080269
string s = "N";
                              ctlDropDownList.Items.Add("Y");
                              ctlDropDownList.Items.Add("N");
                              ctlDropDownList.Items.Add("E");

                              int i = ctlDropDownList.FindControl(s);=========> there is no findcontrol for string
                              ctlDropDownList.SelectedIndex = i;

thanks,

I fink the dropdown should default to whats on the datagrid

thanks
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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

721 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