How do I add button dynamically on ArcGIS Silverlight API? - c#

How do I add button dynamically using C# on ArcGIS?
I can create that using XAML, but I can't write that on C#, I checked on the website on ArcGIS, they allowed to add graphics dynamically, but there is no sample to show how to add controls such as button dynamically.
Can anyone provide me some sample code?
Thanks

Add an ElementLayer to your map (ether in xaml or in code ), then add your button to the element layer.
MyMap.Layers.Add( new ElementLayer() { id="myElementLayer" } )
// create your button.....
MyMap.Layers[ "myElementLayer" ].Add( myButton );
there is an online sample here

Use code behind to add the button during runtime. Anything you do in XAML can be done in code behind.

Related

Possible to have dynamic content with accessable controls in asp.net/C#

I really hope that someone can help, pointing me in the right direction. I'm still new to the more advanced features of asp.net / C#.
What i need is a div, in that div i would want some informations from the database. furthermore i want a textbox with a number and an arrow up and down to increase/decrease the amount in the textbox. And at last a button outside the div to submit the value.
Now the tricky part (for me), is that one div is not enough, I need one div for each "person" in the database. i can easily make that, but.. if i add it dynamically from the .aspx.cs file i am not able to access the value like : textbox1.text; because textbox1 does not exist in the code before it is created.
I have looked at listview and a repeater, but those seems more like they're for making lists, and i need more than that, as i need some functionally too.
The way i would do it now is to add the div by innerhtml. and then adjust the amount by a for loop which also inserts the information from the database which i got in an array. But as said, that doesn't really do the trick when i need to access the textbox and stuff.
Thanks in advance for just looking at it.
EDIT:
I'm not looking for at complete solution, i just want some directions.
I will asume by your post description that by asp.net you mean webForms. If you're new on asp.net development, you have to know that there are different development, in the past (but still very commonly used) you would use WebForms, now at days the trends are using asp.net MVC framework.
now back to your question:
in asp.net WebForms, you have your code defined in two sides: your markup (HTML code normally in a .aspx file) and your code-behind (c# or vb code normally in a .aspx.cs or .aspx.vb).
what I would suggest you to do, is to add your logic for retrieving data from your database in your page_load() function of your code-behind, with this data you would normally use a loop to read all your results and for each result you would create your div with your textbox inside (the trick is using native .net framework classes instead of inserting the HTML directly). a simple example:
protected void Page_Load(object sender, EventArgs e)
{
string[] personsIDs; //<-- this came from your database
Dictionary<string, TextBox> textBoxes = new Dictionary<string, TextBox>();
foreach(string personID in personsIDs)
{
TextBox personTextBox = new TextBox();
personTextBox.ID = "textBox"+personID;
textBoxes.add("textbox"+personID, personTextBox);
}
I explain you:
first, I'm assuming there is an array of the personsIDs, so I created a dictionary (key -> value object) using strings as keys and TextBoxes as values.
then using a foreach I read all the personsID's, and for each one of them I create a new TextBox UIControl and add it to the dictionary using the personID as key. I also added its ID property as "textbox"+PersonID.
this way you can access your textboxes from code-behind by using your dictionary:
textBoxes["textbox"+personID] //(e.g: textBoxes['textBox11'])
but also, since your textBox.ID is equal to textbox+personID, you can also reference it after page has been rendered (e.g. using javascript).
now to add this controlers to your page, just use a container(UIControl) that already exists on your page, and use
container.controls.add(textbox);
this process can be expanded for extra elements, for instance:
1.- have a main placeholder already defined in your page:
<asp:Panel ID= "Panel1" runat = "server">
2.- in your code-behind for each person create a new panel and add all the elements you want inside that panel:
//this goes inside your foreach
Panel innerPanel = new Panel();
TextBox textBox = new TextBox();
Label label = new Label();
innerPanel.controls.add(textbox);
innerPanel.controls.add(label);
////
finally add your innerPanels in to your main panel:
panel1.controls.add(innerPanel);
so there you go, that's basically the idea, hope this helps.

About Page on Windows 8 application

i'm trying to create a tab called about page under the setting in the charm(right bar). I want the tab About inside the settings and when clicked , it will load the information inside the snap view itself. I'm coding in C# , anyone have any idea about this?
Regards,
Binary
Yes, you have to register your About "page" as a SettingsCommand in order to get it to show up in the Settings charm.
I think you want an about link to show up when the user brings up the settings pane - and when clicked - that should show an about page in the settings pane itself - right?
If so, have a look at the Callisto project on github: it has a SettingsFlyout which you could use as follows:
var settingsFlyout = new SettingsFlyout();
settingsFlyout.Content = new YourSettingsControl(); //this is just a regular XAML UserControl
settingsFlyout.IsOpen = true;
Now, all you need to do is execute the code above, when the user clicks on your settings link. As to how the link itself shows up in the settings pane, see the App settings sample on MSDN.

Creating dynamic hyperlink in asp.net using c#

In my application I have DataSet containing name and Id of user and I want to create a dynamic hyperlink of the all the user name. Please anyone tell me how to create dynamic hyperlink using C#.
As #Ashley John said,
HyperLink DynLink = new HyperLink();
DynLink.ID = "DynLink";
DynLink.Text = "This Link Is been Created Dynamically from code behind";
DynLink.NavigateUrl = "~/TestPage.aspx";
PlaceHolder1.Controls.Add(DynLink);
I have used a placeholder as a container to hold the dynamically generated Hyperlink..
Create a new instance of Hyperlink Control
Set its URL property.
Add the Control to the placeholder(or Gridview controls collection if you are using it inside a Gridview) where you want it to get displayed.
Use a Asp.Net HyperLink control. You can create the url passed to the Hyperlink control by using String.Format().
If you want to create a list of all hyperlinks you could have a look at the Repeater and use Eval("...") in the template to render out the link. That way, you can define more in markup then in code.
We can create Dynamic Hyperlink using following Syntax:
<asp:DynamicHyperlink
ID="string"
Action="Details|Edit|Insert|List"
ContextTypeName="string"
DataField="string"
TableName="string"
OnDataBinding="DataBinding event handler"
OnPreRender="PreRender event handler"/>
For more detail just go to this link. You will get a Demo Project Showing use of Dynamic Hyperlink and Linq.

How do I assign an instance of the Image class to an Image control programatically?

Another noob question from me... Apologies!
My initial code would be as follows (this is simplified):
Image pic = new Image();
pic.ImageUrl = "~/Images/photo.jpg";
pic.BorderColor = "Black";
How can I assign the 'pic' Image object to an Image Control already on my ASP.NET page?
The following doesn't work but illustrates what I'm trying to do:
MyImageControl = pic;
I'm sure there must be an easier solution than:
MyImageControl.ImageUrl = pic.ImageUrl;
MyImageControl.BorderColor = pic.BorderColor;
If you want to dynamically put controls on the page you need to do just that. Have a container then add them to the container. If you have some sort of list or array that you are storing the controls in, you just need to iterate through the collection, setting any properties you need and call container.controls.add(control); You will have to do this every post-back as their state will not be kept.
Using an asp:Panel as your container where you want the controls to show up is the easiest way to style and position the controls.
SOLUTION (moved from original post) :
I have come up with something which works for me but would still be interested if there is a way to do what I've asked above - My solution is as follows.... Rather than having a blank Image Control in my .aspx page, I changed it for a PlaceHolder instead. Then, in the C# code, I can use the following to include my Image on the page:
MyPlaceHolder.Controls.Add(pic);

Need html code of GridView within C# code

I am having an aspx page with a user control in it. The usercontrol contains the GridView. At some place within this usercontrol i need html code of GridView.
Can anybody provide help on how i can get html code of GridView.
Thanks for sharing your time.
The best source is to put a gridview into an aspx page and render it on the browser. On the browser, you can just right-click and View the source. You can copy paste and change accordingly.
What do you mean html code? I'm assuming you don't want to view the HTML code via your browser --> View Source (or alternatively click on the control and view source), but do some sort of extraction/editing in HTML via your code in C#? Is that correct? If so you might be able to use JQuery - but it dpeends on your requirements.
EDIT: You can also try Firebug for Firefox since that can show you client side as code that's coming in from JavaScript, CSS, etc.
i hope i am not too late for answering your question, but your problem can be solved by overriding VerifyRenderingInServerForm
you just got to paste the following code in code behind
public override void VerifyRenderingInServerForm(Control control)
{
}

Categories

Resources