I made a webForm in which I simply put a DropDownList like this :
<table>
<tr>
<td>
<dx:ASPxDropDownEdit runat="server"></dx:ASPxDropDownEdit>
</td>
</tr>
</table>
How can I programmaically add item in it ? I would like to display simple text (like "Item1", "Item2, ...) when clicking on the down arrow of this element.
From: ASPxDropDownEdit Overview
The ASPxDropDownEdit represents an editor containing an edit box to
display the editor value and a specific button, that opens a dropdown
window whose content can be templated. The main purpose of the
ASPxDropDownEdit is to allow you to define its value based upon the
value(s) of other control(s) integrated into the editor's
DropDownWindowTemplate.
As per the documentation, you can not use it as like a combo box control. I suggest you use ASPxComboBox, which let you implement this functionality in easy way.
If you desperate to implement the DropDownEdit control then you need to create its DropDownWindowTemplate programmatically. Follow the below approach and you can try to implement what you want to accomplish.
// Assign DropDownWindowTemplate property to custom template
protected void Page_Load(object sender, EventArgs e)
{
ASPxDropDownEdit1.DropDownWindowTemplate = new CustomTemplate();
}
//Template class that implement ITemplate interface.
public class CustomTemplate:ITemplate
{
public void InstantiateIn(Control container)
{
ASPxListBox listBox = new ASPxListBox();
listBox.Items.Add("Item 1");
listBox.Items.Add("Item 2");
listBox.Items.Add("Item 3");
container.Controls.Add(listBox);
}
}
Refer this:
Creating Web Server Control Templates Programmatically
Related
Currently, I am using RadTreeView Telerik control for showing hierarchical data along withadd/edit/delete functionalities for each node. Using TreeView - Context Menu, that has been achieved, but I am trying to implement it as shown in below:
It works the following way:
a) When a node is expanded by clicking "+" icon, "Add Group" button is visible at the bottom of its last child.
b) When a node is selected, "Edit" and "Delete" icons appear.
On clicking any of those icons will open a Dialog for respective actions.
So, I need to replace Context Menu with the display shown in mock. I tried to use NodeTemplate something like below:
<NodeTemplate>
<div>
<span>Test</span>
</div>
</NodeTemplate>
but, it makes the text of all nodes as "Test".
Can somebody please help me out?
<script type="text/javascript">
function OnClientContextMenuItemClicking(sender, args)
{
var menuItem = args.get_menuItem();
var treeNode = args.get_node();
menuItem.get_menu().hide();
switch (menuItem.get_value())
{
case "edit":
treeNode.startEdit();
break;
}
}
</script>
Hope this helps,
I implemented the RadTreeView in serverside. I though it is easy to manage in server side, specially when it comes to binding and handling the events
This is my Default.aspx.cs
using Telerik.Web.UI;
public partial class Default : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
}
protected void RadTreeView1_NodeEdit(object sender, RadTreeNodeEditEventArgs e)
{
// This is the serverside event that is triggered on Edit
RadTreeNode nodeEdited = e.Node; // This is the current node that is clicked
string newText = e.Text;
nodeEdited.Text = newText;
}
//
//.........
//.........
}
This is something extra. In server-side you can also find a node like this,
RadTreeNode node = RadTreeView1.FindNodeByText("TestOne");
// now edit and change any test
node.Text = "Test";
I hope this helps.
I have a sharepoint web part where I am programatically adding a button to the page. When the button renders, it has no name or ID. I am doing the following in the code behind of the web part:
public class ChartControl : WebPart
{
protected Button BubbleChartApplyButton;
protected override void CreateChildControls()
{
BubbleChartApplyButton = new Button {Text = "Apply This"};
}
protected override void RenderWebPart(HtmlTextWriter output)
{
BubbleChartApplyButton.RenderControl(output);
}
}
and this is what gets rendered:
<div WebPartID="4844c2e5-2dd5-437b-a879-90c2e1e21f69" HasPers="false" id="WebPartWPQ2" width="100%" class="ms-WPBody ms-wpContentDivSpace" allowDelete="false" style="" >
<input type="submit" value="Apply This" />
...more output here...
</div>
Notice how the input tag gets rendered with no name and no id... I would expect to see something like ID="ctl00$m$g_2d506746_d91e_4508_8cc4_649e463e1537$ctl13" or something.
Any ideas as to why the button control is not rendering with the name and IDs that .NET normally generates?
Thanks,
Ryan
Ugh, it was a simple thing I overlooked. So I am creating the control and rendering it to the output so it shows up when the page is rendered. BUT, in order for it to be dialed into the control tree so that ASP.NET assigns IDs and I can wire it up to an event handler, I MUST specifically add it to the control tree.
So I also needed to do this:
protected override void CreateChildControls()
{
BubbleChartApplyButton = new Button {Text = "Apply This"};
Controls.Add(BubbleChartApplyButton) //<== ADD TO THE CONTROL TREE BEAVIS!
}
Have you tried something like:
BubbleChartApplyButton = new Button {Text = "Apply This", ID = "myButtonID"};
I want to create a user control that will again contain a user control that will be dynamically generated and can be repeated N times with respect to data present in data table.
How can i do this.
You want to use TemplateControl.LoadControl (which both Page, UserControl and MasterPage inherit from). You need to do this during the Init event for postback stuff to work.
void Page_Init(Object Sender, EventArgs e) {
var control = LoadControl("Awesome.ascx");
// ... Magic!
}
Place a placeholder control on the parent user control:
<asp:PlaceHolder runat="server" id="phMainHolder" />
In the Page_Load or Page_Init event you simply instantiate the child user controls in a for(each) loop and add them to the placeholder like for example:
for(int i = 0; i < 10; i++) {
ChildUC child = new ChildIC();
phMainHolder.Controls.Add(child);
}
This is the bare minimum to do it. You can opt to set properties or whatever on your child controls of course.
The class ChildUC is a fictive class name for this example. Use the class, and if needed use the namespace as extra in which it is defined, of the user control you want to use.
I have a control placed in edit item template in detail view control. what ever the control I am using I need to access those values in my code behind page that in my item updating event
Can any one tel me the syntax how to acces it those control values?
Actually what ever control are there in my edit item template are not added in my designer.cs file what is the issue for this
thank you
this will definitly work try..
protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
TextBox txtbox = (TextBox)DetailsView1.FindControl("YourControlID");
}
I am building a pop-out menu, and the client wants it to be able to pop out continously based on a heirarchy.
For example, the first pane is a list of options. When they are hovered over, another pane should pop up next to it with the next level of options, and so on until the last level of options is reached.
I can handle all the javascript and stuff, but I can't think of a way to continously embed repeaters inside repeaters. I know I could do it once by putting a repeater inside another, but then I would only have two layers.
I need to be able to continously embed repeaters for each layer of options, or achieve this with a similar technique using a different control.
Any help is great, thanks!
You won't be able to build this in mark up. You'll have to add the controls dynamically in your code behind by building the Repeater for each level and adding it to the previous Repeater's template. It will require a full postback for each option selected because the nested Repeater could potentially be of different depth depending on which option is chosen.
You might be better off doing this all client-side, though, using AJAX and javascript. When an option is chosen, fire off an AJAX request to see if that option has sub-options. If it does (return them), then dynamically build the new options control using javascript and add it to the page. When a different option is chosen, you'll remove the elements from the DOM holding the previously chosen options sub-options.
If you can get your menu out in form of a list of MenuItem objects, each of which has a (sometimes empty) list of sub items (and I really mean a List<MenuItem> here... we're going to use this collection as a datasource for a sub-repeater, so it needs to implement IEnumerable<T>) as a property MenuItem.SubItems, you could probably make use of a UserControl that loops out one menu level, and calls upon itself for the next.
In the UserControl you'd have something like this:
<li><a href='<%= this.MenuItem.Url %>'><%= this.MenuItem.LinkText %></a></li>
<asp:Repeater ID="UCRepeater" runat="server">
<HeaderTemplate>
<ul>
<ItemTemplate>
<menu:MenuItem ID="MenuItemUC" runat="server" />
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
The UserControl in the ItemTemplate is the same one, so for each item template the same thing will be rendered.
Below is the Code Behind for this user control, and this is where the magic happens:
public partial class MenuItemUserControl : UserControl
{
// A property we'll use as the data source
public MenuItem MenuItem { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
// If the current menu item has sub items, we bind the repeater to them
// And by the way, there is no use doing this on every postback. First
// page load is good enough...
if(!Page.IsPostBack) {
{
if(MenuItem.SubItems.Count > 0)
{
UCRepeater.DataSource = MenuItem.SubItems;
UCRepeater.DataBind();
}
}
}
protected void UCRepeater_OnItemDataBound(object sender,
RepeaterDataBoundEventArgs e)
{
// Every time an Item is bound to the repeater, we take the current
// item which will be contained in e.DataItem, and set it as the
// MenuItem on the UserControl
// We only want to do this for the <ItemTemplate> and
// <AlternatingItemTemplate>
if(e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
var uc = (MenuItemUserControl)e.Item.FindControl("MenuItemUC");
if(uc != null)
{
// This is the magic. Abrakadabra!
uc.MenuItem = (MenuItem)e.DataItem;
}
}
}
}
So in order to get this to work, the only thing missing is really a nice way of getting your data out as a hierarchical list of MenuItems. This I'll leave to your data access layer (and it would be cheap easy using LINQ to SQL or Entity Framework... ;) )
DISCLAIMER: This code is provided as is, and I wrote it off the top of my head. I have not tested it, but I think it will work - and if it doesn't, it could at least give you an idea of how to solve the problem. If you have problems, please post them in comments and I'll try to help out - but there are no promises of success here. Just a willingness to help out! =)