adding url to the hyperlink field in gridview - asp.net

I have a dynamic grid view. I add column in page load.
I use this code for add Hyperlinkfield :
string[] url = new string[1];
url[0] = field.InternalName;
HyperLinkField link = new HyperLinkField();
link.HeaderText = field.Title;
link.DataNavigateUrlFields = url;
link.DataNavigateUrlFormatString = "{0}";
link.DataTextField = field.InternalName;
link.SortExpression = field.InternalName;
grid.Columns.Add(link);
my problem is : for example my url is "http://Test1.docx, http://Test1.docx".
I want navigateurl set "http://Test1.docx" .

If I am understanding correctly what the issue is. The field.InternalName field contains "http://Test1.docx, http://Test1.docx" to which you are assigning to a string array and you are trying to attempt to only get the first value before the comma.
In that case, you will need to split the string:
string[] urlSplit = field.InternalName.Split(',');
link.DataNavigateUrlFields = urlSplit[0];

Related

How to get the selected value from a dropdown in MVC to use inside the view

I have an MVC app with leaflet running in it, I am parsing xml data to get the paths to the leaflet tiles which I then display in a drop down via a ViewData["value"]. The problem is I can't seem to figure out how to get that selected value and pass it down to the leaflet js as a path and then display everything. I tried many different ways to get the selection data but I'm just hitting a wall again and again.
The below code is how I send it to the view. I display it via an #Html.DropDownList("layerType", ViewData["value"] as List)
string outputPath;
outputPath = ConfigurationManager.AppSettings.Get("outputPath");
XmlDocument xDoc = new XmlDocument();
xDoc.Load(outputPath + #"\log.xml");
XmlNodeList layerType = xDoc.GetElementsByTagName("layerType");
XmlNodeList layerPath = xDoc.GetElementsByTagName("layerPath");
XDocument doc = XDocument.Load(outputPath + #"\log.xml");
var count = doc.Descendants("layers")
.Descendants("layerData")
.Count();
List<SelectListItem> li = new List<SelectListItem>();
foreach (int i in Enumerable.Range(0, count))
{
li.Add(new SelectListItem { Text = layerPath[i].InnerText, Value = i.ToString() });
}
ViewData["value"] = li;
return View(li);
How would I get the selected data and simply pass it down into the leaflet part inside the js tags.
Would I maybe pass it back into a controller and then back to the view?
#Html.DropDownList("layerType",
new SelectList((IEnumerable) ViewData["value"]), "Value", "Text")
In the Post method, you have to fill the viewdata again to avoid error if model returns invalid
Refer Below Link :
MVC Select List with Model at postback, how?
Working Code
https://dotnetfiddle.net/2lrb2S
Get Value on View
<script>
var conceptName = $('#nameofyourdropdowncontrol').find(":selected").text();
//code for passing value
</script>

Convert object to a string c# xamarin forms

I want to convert a label value (Object) to a string variable but I get an empty string.
Here is the code.
var label = new Label
{
};
label.SetBinding(Label.TextProperty, "Link");
string url = label.GetValue(Label.TextProperty).toString();
I want to use the content of the label as a string.
If I don't convert it the url in the label it's ok but when I convert it I get an empty string as result. Any help? How can I convert this to a string?
Thanks in advance.
You can set the Label text implicitely, but I have a feeling that's not what you're trying to do.
If you want to bind to a Link property from a ViewModel, you probably just forgot to set the BindingContext for your Label.
var label = new Label
{
Text = "Set implicitely"
};
string url = label.GetValue(Label.TextProperty).ToString(); // Set implicitely
MyViewModel viewModel = new MyViewModel
{
Link = "Set through binding"
};
label.BindingContext = viewModel;
label.SetBinding(Label.TextProperty, "Link");
string url2 = label.GetValue(Label.TextProperty).ToString(); // Set through binding
Well I found a very easy solution as #hichame.yessou already mentioned on the first comment.
I was passing data into a label by XAML
<Label Text="{Binding Link}" x:Name="linkLabel" IsVisible="False" />
But I put the "x:name" property in order to handle the label from the xaml.cs file.
Well then all was easy..
string url = linkLabel.Text;

How I can customize the Leemon CMS to filter the content by customzied field?

I'm using Lemoon CMS. I've created a new Content Type, and i've modified it with new fields and all its working fine.
I created a new user control to show some data from my content type which the field ("isFeatured=true")
How I can customize the code to filter the content, and how i can sort the data by custom added field?
ContentQuery query = new ContentQuery();
query.ParentID = 70;
query.MinDepth = 1;
query.MaxDepth = 1;
query.LanguageMode = LanguageMode.Fallback;
query.SearchNonSearchable = null;
query.ContentTypes.Add(typeof(Mindroute.Lemoon.Generated.ContentType.ServiceItem).FullName);
query.ContentTypeMode = ContentTypeMode.Inherit;
//query.OrderBy.Add(new SortItem(ContentColumn.Columns[6], "desc"));
Response.Write(ContentColumn.Columns[6]);
query.PageSize = 8;
Entries = ContentService.Search(query).Cast<Mindroute.Lemoon.Generated.ContentType.ServiceItem>();
First, I think you can simplify your code that gets the ServiceItems. You could simply use ContentService.GetChildren<ServiceItem>(70) instead of setting up a ContentQuery.
To filter and order by a specific property you could then use Linq like this:
var children = ContentService.GetChildren<ServiceItem>(70);
var filtered = children.Where(x => x.IsFeatured == true);
var ordered = filtered.OrderBy(x => x.SomeOtherProperty);
It is also possible to use ContentQuery to find items with custom properties, you would then need to set ContentQuery.PropertyValue = new PersistedValue("IsFeatured", true);

Dynamically creating ASP.NET form controls

I have a form which, based on the answers given in the prior page, can have about 10 different variations in the combination of fields (most are the same, but several change). I decided rather than making 10 separate pages, I would try to make it dynamic. Eventually this will pull the form setup from a database, but for now I'm just trying to get the dynamic part to work. The following code kinda works, but it's giving me a weird result.
private void AddTestControls()
{
var newbox = new TextBox();
newbox.ID = "FirstBox";
newbox.Text = "This is dynamic";
newbox.CssClass = "stepHeader";
DynamicDiv1.Controls.Add(newbox);
var newlit = new Literal();
newlit.ID = "FirstLit";
newlit.Text = ".<br/>.";
DynamicDiv1.Controls.Add(newlit);
newbox.ID = "SecondBox";
newbox.Text = "This is also dynamic";
newbox.CssClass = "step";
DynamicDiv1.Controls.Add(newbox);
}
I've stepped through it and all the properties are getting set correctly, but when the page finally renders, only the SecondBox control is visible. There is no trace of the FirstBox. If I change it so that SecondBox is its own object (newebox2 for example) then both are visible, but with how I was thinking that I would ultimately do the form from the database, this could complicate things. I don't understand why the textbox object has to be recreated in order to add it to the Div's collection of controls. Am I going about this all wrong, or just missing a step somewhere?
Your "SecondBox" are overwriting the "FirstBox" newbox since it's still holding a reference to it. Create a new TextBox for the second box:
var newbox = new TextBox();
newbox.ID = "FirstBox";
newbox.Text = "This is dynamic";
newbox.CssClass = "stepHeader";
DynamicDiv1.Controls.Add(newbox);
var newlit = new Literal();
newlit.ID = "FirstLit";
newlit.Text = ".<br/>.";
DynamicDiv1.Controls.Add(newlit);
// Create a new TextBox
var secondBox = new TextBox();
secondBox.ID = "SecondBox";
secondBox.Text = "This is also dynamic";
secondBox.CssClass = "step";
DynamicDiv1.Controls.Add(secondBox);
I'm not quite sure why this could complicate things, but what you could do is create a method for creating a textbox, if that's easier:
TextBox CreateTextBox(string id, string text, string cssClass)
{
var box = new TextBox();
box.ID = id;
box.Text = text;
box.CssClass = cssClass;
return box;
}
And then
var newBox = CreateTextBox("FirstBox", "This is dynamic", "stepHeader");
DynamicDiv1.Controls.Add(newBox);
What's how it suppose to work. newbox1 is a reference so after the first time it's added to DynamicDiv1, it's there and if you change its Text, then the Text will be changed. You may find this SO useful. This SO demostrates the same issue you are having.

Get value from jQuery in asp.net code nugget?

How can I get the value from a select field (dropdownlist) into a "code nugget" using jQuery? I have seen this done, but can't find an example of it now.
I have two dropdownlists, and I want to get the selected values from them and concatenate it into an id parameter to send to an action method:
$.get('<%= Url.Action("GetTasks","Timesheet", new { id = [Concatenated value here] } %>'
How can I get the concatenated selected values from the two dropdownlists with jQuery?
You could try something like this:
var url = "<% Url.Action("GetTasks", "Timesheet", new { id = "{0}" }) %>";
var selected = $("#mySelect").val().join(",");
url = url.replace("{0}", selected);
$.get(url);

Resources