Solved

DropDownlist control

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

Independent Software Vendors: 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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

735 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