Solved

DropDownlist control

Posted on 2006-07-11
3
218 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 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

Technology Partners: 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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

628 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