Custom control - double control when in edit mode?

 I created a custom control class like following! When in normal mode it's a div and when in edit mode it is a dropdownlist! 
1    public class Label2DropDown : BoundField
2 {
3 private string dropMember;
4 public string DropMember
5 {
6 get { return dropMember; }
7 set { dropMember = value; }
8 }
9 10 ///<summary>
11 ///Builds the contents of the field
12 ///</summary>
13 protected override void InitializeDataCell(DataControlFieldCell cell, DataControlRowState rowState)
14 {
15 if ((rowState & DataControlRowState.Edit) == 0)
16 {
17 HtmlGenericControl div = new HtmlGenericControl("div");
18 div.Attributes["class"] = "lable2Drop";
19 div.DataBinding += new System.EventHandler(div_DataBinding);
20 cell.Controls.Add(div);
21 }
22 else 23 {
24 DropDownList drpEdit = new DropDownList();
25 drpEdit.DataBinding += new System.EventHandler(drpEdit_DataBinding);
26 cell.Controls.Add(drpEdit);
27 }
28 29 base.InitializeDataCell(cell, rowState);
30 }
31 private void div_DataBinding(object s, EventArgs e)
32 {
33 HtmlGenericControl div = (HtmlGenericControl)s;
34 //get the field value 35 object value = this.GetValue(div.NamingContainer);
36 37 //assign the formatted value 38 div.InnerText = this.FormatDataValue(value, this.HtmlEncode);
39 }
40 41 private void drpEdit_DataBinding(object s, EventArgs e)
42 {
43 DropDownList drpEdit = (DropDownList)s;
44 //get the field value 45 object value = this.GetValue(drpEdit.NamingContainer);
46 47 //assing the formated value 48 String[] sDrop = dropMember.Split('|');
49 foreach (string sTemp in sDrop)
50 {
51 drpEdit.Items.Add(sTemp.ToLower());
52 }
53 54 drpEdit.SelectedValue = value.ToString().ToLower() ;
55 }
56 }

 
But when in edit mode it has 2 controls like this:

Please help me! I don't know why! 

0
vuanhviet
2/12/2007 4:26:33 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

2 Replies
901 Views

Similar Articles

[PageSpeed] 46
Get it on Google Play
Get it on Apple App Store

Try it without calling base.InitializeDataCell(cell, rowState); on the base object. The InitialIzeDataCell adds the text box, basically what is happening, is you are adding the DDL, then calling the base function to add the textbox as it normally would, so the textbox just gets added to the controls list.
0
jstreet0204
2/12/2007 5:26:54 AM

It's work! Thank you!

I have another question i try to get updated value from the GridView in edit mode but i can't! Here my code in update procedure! I build multi-tier web application so i want to manual update but i can't find any way to get the updated value! Please give me a properly solution! Thank in advanced!

 

1    protected void gvContent_RowUpdating(object sender, GridViewUpdateEventArgs e)
2        {
3            if (Page.IsValid)
4            {
5                //get the id of category currently edited
6                int categogyID = (int)gvContent.DataKeys[e.RowIndex].Value;
7                //update the values
8                Gen.WebModules.CMS.Business.CMSCategory category = new Gen.WebModules.CMS.Business.CMSCategory(categogyID);
9                if (e.NewValues["Description"] != null)
10               {
11                   category.Description = e.NewValues["Description"].ToString();
12               }
13               if (e.NewValues["Lang"] != null)
14               {
15                   category.Lang = e.NewValues["Lang"].ToString();
16               }
17               if (e.NewValues["Visible"] != null)
18               {
19                   category.Visible = bool.Parse(e.NewValues["Visible"].ToString());
20               }
21               category.Update();
22   
23               gvContent.EditIndex = -1;
24               BindGridView();
25           }
26       } 
 
0
vuanhviet
2/12/2007 8:14:32 AM
Reply:

Similar Artilces:

Custom Control within a Control Control
I am developing a custom controls that will render headers for different web sites. Within these controls, I want to place another custom control that will change the language. I created the language control and had it implement IPostBackDataHandler. This control works fine if I drag it on a new web form, but if I tell a header custom control to render it problems occur. The Language Selector custom control does not have a Page member anymore and the event handlers do not work. Does anyone have any experience with doing something similiar? Anyone have any suggestions? Thanks, ...

how to have both server controls and html controls rendered in a custom control?
I have a custom control in which there is an html text box.when you click on it , a div containing a table is appeared and according to what you select in that table a text is set to the text box. It works fine but the problem is: as the text box is an html element it doesn't have viewstate and when a post back occures in the page its value disappeares.I tried a hidden field to keep its value.again there is another problem : I put this custom control in a usercontrol and put the usercontrol in a multiview and by clicking on a button this view is selected and by clicking another bu...

How do I control one control from another control?
I have a page page1.aspx which is within a master page. On page I have a table with two cells. Within each cell I have placed two controls (ascx) that I have developed. Now I'd like to be able to get these two controls to interact. One needs to update the other. One has some search criteria that the other one needs to update its gridview. One needs to make the other visible/not visible at certain times. Out of the box neither control can see each other at all. Is there a good article or someplace I can find some information on how to do this?  AllAboutFocus.com. Information Technolo...

Custom Control within a Custom Control
I have two individual custom controls say custom cc1 and cc2. cc1 is communicating to cc2 using event delegate mechanism.I have tested the behaviour by dropping cc1 and cc2 onto a Web Page and it works fine. I want to create a third custom control say cc3 which should contain both cc1 and cc2. So that if i drag and drop cc3 onto a Web Page i can acheive exactly what i am doing above. The problem is that i am not sure how to call/register a custom control within a custom control ? Any clue ? Thanks!! Hi, Do you mean adding custom control to custom control? I think you can use the same wa...

Add .Net Control to Web Custom Control
 I want to add .NET Control (like: TextBox, Button...) to Web Custom Control.How i can do it? Alphavn That's called a composite control -- "Mark As Answer" if my reply helped you -- Hello Guys What gunteman said, that is one approach and in most cases the right one.But its also possible to add child controls to a Control thats inherit from WebControl itself. Be sure to implement INamingContainer to that inherited Control too, thats the important point of that approach.--Microsoft MVP - Visual Developer ASP / ASP.NET- http://www.aspnetzone.de/blogs/peterbuch...

Architecture: .Net Controls vs. Custom Controls
I'm interested in managing users. i.e. Logins and profiles, etc.My question is, should I be using things like the Login control or should I program these from scratch? I dont like the fact that .NET creates so many things for me. This level of abstraction terrifies me and it feels like I have no control over the code .I've done a few huge sites in Classic ASP (million-hits-per-day type sites) and I'm not sure how robust certain controls are, or when to use them.Is, for example, the Login control aimed at newbies to .NET? Should it be used for the larger projects with thousands of...

DW control in VB. NET custom control
Hi Just attempting to investigate some DW.NET aspects. In regards to building a ancestor object with VB.NET, why is when I create a datawindowcontrol custom control that any reference to it is like (assuming that u_dw is the name of the DW control): custom_control.u_dw.DatawindowObject = "myDW" instead of simply: u_dw.DatawindowObject = "myDW" If I create a .NET custom control with a button on it, I can directly reference the button's methods and properties without having to qualify it with the custom control's name. When I was developing with po...

ajax.net controls used in custom composite controls?
I am creating an events calendar that uses the accordion to display the events for the selected day.  The problem I'm having is that the accordion is not responding to any client side events.  I would really like to find a good "How to" article for building composite controls that incorporate an ajax.net control like the accordion....

Handling control events while in edit mode for a gridview control
I have a dropdownlist and checkbox in a single column of a gridview. While the row is in edit mode, I want to set the visibility of the checkbox based on the value selected in the dropdown list. I can do this easily enough  when the row is first put into edit mode, but how do I access the dropdown list's change event when the row is already sitting there in edit mode? Thanks for any help you can provide.   Penny Penny, Just create a SelectedIndexChanged event like below. Create a row object for the currently edited row, find the checkbox you want to control, then set the Visib...

user control or custom control ?
i have datagrid which shows monthyear user control for each row. The month year user control has two drop down list. one is for year and other one is for month. So for each row in particular column i'll have that user control loaded. it works fine but ut takes lot of time in rendering when there are 200 rows. what would be the solution. will custom control help? Hi,Lax4u: Some tips i am not quite sure. First, you can disable the viewstate of the userControl to make it not load so many information in each postback and store the necessary in the global range. Second, Caching porting of th...

Custom controls called from inside other custom controls???
I'm fairly new to writing controls in ASP.NET so, forgive the I am trying to create a base page class which will call 3 custom controls. This base page class will span across multiple projects hence the reason I am not creating user controls. These 3 custom controls are: 1. TopNav-uses render method to display an HTML table with graphics for top navigation. 2. ImagePairs-uses prerender method to add javascript code to manage what graphic is displayed in TopNav onMouseOver and onMouseOut 3. MgrHeader-uses render method to display an HTML table with s...

Custom controls having Ajax Controls
I have a custom control called ModalUpdateProgress. I don't want to narrow down the topic to why do I have to build it or something else. The point of control is to lock a sceen while postback happens so it is a conjunction of Update Progress and Modal Popup Extender. I had no problem to build a control similar to Update Progress. Then I add Modal Popup Extender:   if(typeof(undefined) != typeof(AjaxControlToolkit)) if(typeof(undefined) != typeof(AjaxControlToolkit.ModalPopupBehavior)) { this._modalPopupBehavior = $create(AjaxControlToolkit.ModalPopup...

Access controls in custom controls
I have loaded user control into placeholder, but how to access controls inside it? Aka controls inside controls? Hi,the PlaceHolder is the container of your controls. To reference a control inside a container, you can use the FindControl() method of the container, passing the ID of your control as an argument.For example:// Create an instance of the user control.MyUserControl uc = new MyUserControl();// Give an ID to the user control instance.uc.ID = "userControl1"; // Add the user control to the PlaceHolder.myPlaceHolder.Controls.Add(uc);        &nb...

Creating Custom Controls With Custom Controls Inside Of Them
Hello, I am trying to create a custom control for creating tabs. The idea is that our designer can just use the control tags to generate the tabs.  The problem that I am running into is that I want to be able to have a custom control that allows any number of child custom controls. So there would be a TabContainer Control, and within that there would be any number of tabs.  The idea is similar to how an asp:DropDown list can have any number of ListItems within them.  Here is my code, any help is appreciated. 1 <!-- TAB CONTAINER -->2 <%@ Control Language=&...

Custom Controls or User Controls
Hi, I have to create a menu control and I am unable to decide between a custom control or user control.  Apart from the fact that a custom control can be inserted into the toolbox what are the other advantages and disadvantages of each like performance, and so on.  Plus how do I decide between the two. Thanks Arjuna. Hello Please refer to the KB article Overview of user controls vs. custom controls Hope it helps, JessicaJessica CaoSincerely,Microsoft Online Community Support“Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer...

Web resources about - Custom control - double control when in edit mode? - asp.net.presentation-controls

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Now you can control your GoPro Camera from Apple Watch
One of the nicest features of the GoPro camera is the ability to control it using the iPhone app. With the GoPro App , you can easily control ...

Arizona leaders welcome 'Leave No Child Behind' successor, less federal control
azcentral.com Arizona leaders welcome 'Leave No Child Behind' successor, less federal control azcentral.com The Senate gave final approval ...

FTC and healthcare cost control
... Pennsylvania, and lead to reduced quality and higher health care costs for the area’s employers and residents….the merged entity would control ...

Google seems more determined than ever to take control of Android
... to ad money. However, Google grabbed the lion’s share of the smartphone market by giving Android away. That means it lost the ability to control ...

Fox Presents Ben Stein As An Awesome, Stupendous Gun Control Genius
Fox News host Neil Cavuto was super-impressed with “great writer and thinker” Ben Stein's opposition to gun control. “The problem is not gun ...

Krauthammer: Jihadists ‘Are Not Going To Be Held Back By The Niceties Of The Gun Control Laws’
Krauthammer: Jihadists ‘Are Not Going To Be Held Back By The Niceties Of The Gun Control Laws’

The NFL Should Seize Control Of The Cleveland Browns
Drew Magary’s Thursday Afternoon NFL Dick Joke Jamboroo runs every Thursday during the NFL season. Email Drew here . Read more...

Shocking Facts About U.S. Gun Control
The Second Amendment has been the subject of debate for centuries now, and you might be surprised to find where that still-unsettled dispute ...

GoPro brings Apple Watch control to its cameras
While it's possible to control a GoPro camera using a smartphone or remote, the company just added a device option that might be simpler: the ...

Resources last updated: 12/10/2015 7:56:09 PM