Solved

DropDownlist control

Posted on 2006-07-11
3
211 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
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 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

Free Trending Threat Insights Every Day

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

14 Experts available now in Live!

Get 1:1 Help Now