473,386 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

(C#) DropDownList Using SelectedIndex w/ onDataBinding

42
I have a DataGrid and a column that changes into a DropDownList when edited:

Expand|Select|Wrap|Line Numbers
  1. <columns>
  2.     <asp:templatecolumn headertext="Role Type">
  3.         <itemtemplate>
  4.             <asp:hyperlink id="hlinkRoleType" navigateurl='<%# "contact_roles_details.aspx?id=" + DataBinder.Eval(Container, "DataItem.ID", "{0}").ToString() %>' Text='<%# DataBinder.Eval(Container, "DataItem.Role", "{0}").ToString() %>' runat="server"/>
  5.         </itemtemplate>
  6.         <edititemtemplate>
  7.             <asp:dropdownlist id="ddlRoleEdit" datavaluefield="ID" datatextfield="Name" datasource="<%# FillRoleList() %>" ondatabinding="ddlRoleEdit_ItemDataBound" runat="server" />
  8.         </edititemtemplate>
  9.     </asp:templatecolumn>
  10.     <asp:editcommandcolumn buttontype="LinkButton" edittext="&lt;img src=&quot;images/edit_icon.gif&quot;&gt;" />
  11.     <asp:buttoncolumn text="&lt;img src=&quot;images/delete_icon.gif&quot;&gt;" commandname="deleteRole"></asp:buttoncolumn>
  12. </columns>
I've spent many many hours trying to set the default value of the DDL to whatever was present before editing. Everything I've inserted into the *** below stirs up some petty technical error in C#:

Expand|Select|Wrap|Line Numbers
  1. public void ddlRoleEdit_ItemDataBound(Object sender, DataGridItemEventArgs e)
  2. {
  3.     DropDownList ddl = (DropDownList) sender;
  4.  
  5.     ddl.SelectedValue = ***
  6. }
  7.  
Dec 10 '07 #1
1 5410
spamguy
42
Still having no luck. In addition, I used the wrong EventArgs type, even though I swear it worked at one point. The corrected C# code is below. With plain old EventArgs, it's even harder than before to do what I want.

Expand|Select|Wrap|Line Numbers
  1. public void ddlRoleEdit_ItemDataBound(Object sender, EventArgs e)
  2. {
  3.       DropDownList ddl = (DropDownList) sender;
  4.       ddl.SelectedValue = ***
  5. }
Dec 12 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Stanley J Mroczek | last post by:
How do you load a dropdownlist when edit is clicked in a datagrid ? <Columns> <asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True" HeaderText="Option...
0
by: Shane O. Pinnell | last post by:
I am sure this has come up before, but I haven't been able to find an answer as of yet. That said, any help is definitely appreciated! I have a datagrid populated from a dataset. I have a...
10
by: dhnriverside | last post by:
Hi guys Still having a problem with this dropdownlist. Basically, I've got 4. The first 2 work fine, then my code crashes on the 3rd. ddlEndTimeHour.Items.FindByValue(endTime).Selected =...
0
by: fwirtanen | last post by:
I am building a custom composite control consisting of two drop downs, with parent/child dependancy. The child dropdownlist is updated through client callback when the parent index changes. ...
4
by: Mark Waser | last post by:
I've discovered a very odd bug when attempting to put a dropdown list in a datagrid. In the page PreRender step, the selected index of the datagrid is successfully set during databinding. Yet,...
3
by: =?Utf-8?B?ZGVuIDIwMDU=?= | last post by:
Hi, Trouble in retaining values of dropdownlist, textboxes, and other controls when dropdownlist selectedindexchanged event is triggered, the controls are inside a user control and this user...
1
by: marcbb | last post by:
Hi all, I have a really strange problem working with Dropdownlists in a DataGrid. I'm trying to preselect some values from the DropDownlist for each row in the DataGrid, but it seems that...
2
by: spamguy | last post by:
Assume a DataGrid that, during edit mode, has two DropDownMenus, ddlA and ddlB. Upon clicking 'Save,' the app performs the simplified task of copying the DDL values of each to a label. public...
3
by: =?Utf-8?B?Y21lZWsxXzE5OTk=?= | last post by:
Hello, On a webpage, create an UpdatePanel with two DropDownLists. Set AutoPostBack of DropDownList1 to true. In the SelectedIndexChanged method, refill DropDownList2 and set the focus to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.