I'm trying to get selected Item Text and value of RadListBox in Transferred event.
I tried following code:
protected void listbox_Initial_Transferred(object sender, RadListBoxTransferredEventArgs e)
{
string id = e.Items[0].Value.ToString();
string description = e.Items[0].Text.ToString();
}
here i passed "0" as index. Its working fine.
Now i got stuck here to fetch the selected index of Item.
Looking forward for your comments and replies.
Thanks.
Please try with the below code snippet.
// for single item
string id = RadListBox1.SelectedItem.Value.ToString();
string description = RadListBox1.SelectedItem.Text.ToString();
// for multiple item
foreach (RadListBoxItem item in RadListBox1.SelectedItems)
{
string _id = item.Value.ToString();
string _description = item.Text.ToString();
}
AS per your sample code, please also try with the below code snippet.
// for multiple item
foreach (RadListBoxItem item in e.Items)
{
string _id = item.Value.ToString();
string _description = item.Text.ToString();
}
Related
I have a list(registration) with fields like username,pwd ,name,age etc.
i want to send a mail to admin with all the fields (username,pwd,age etc...) when a new item is added to the custom list.i tried by using added event but i am unable to get the values of the newly added item.
it is entering into the if loop but at the next line i am getting an error object reference not set to any instance.
Thanks in advance
i am new to SharePoint
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
SPWeb oSPWeb = properties.OpenWeb();
//GETTING THE LIST NAME
String curListName = properties.ListTitle;
if (curListName == "registrtion")
{
//FETCH THE DATA OF THE NEW ADDED ITEM IN THE LIST
string EMPLOYEENAME = properties.AfterProperties["EMPLOYEENAME"].ToString();
}
}
Use this instead:
string EMPLOYEENAME = properties.ListItem["InternalFieldName"]
Make sure you use the internal name of the field, check here how to get that name:
http://sharepoint-works.blogspot.com.au/2012/06/internal-column-name-in-sharepoint-list.html
I am building a complex WFFM user control that extends BaseUserControl. This control has multiple fields that get prepopulated based on some business logic. One of the fields is supposed to be a drop down which shows values from a series of Sitecore items. Here is the definition of my ListField property:
private string myListField;
[VisualProperty("My List Field:", 100),
VisualCategory("Appearance"), VisualFieldType(typeof(ListField))]
public string MyListField{
get { return myListField; }
set { myListField= value; }
}
When I debug this, the content of titleFieldList is a string that contains the following XML in URL encoded format:
%3Cquery%20t%3D%22root%22%20vf%3D%22__ID%22%20tf%3D%22Value%22%3E%3Cvalue%3E%7B814FC177-2750-48D6-B7B7-4EE87012C637%7D%3C%2Fvalue%3E%3C%2Fquery%3E
which, decode, is:
<query t="root" vf="__ID" tf="Value">
<value>{814FC177-2750-48D6-B7B7-4EE87012C637}</value>
</query>
I understand the meaning of this XML. It says that all the children of the item whose ID is that Guid are supposed to be used to populate my list, using the template field "__ID" for the value and the template field "value" for the text.
Can someone help me understand what am I supposed to do to bind an asp:DropDownList to this? Is this a particular sitecore object that has been serialized and encoded?
Is there an sc:control that can handle this?
Thanks!
** EDIT **
So I tried the following piece of code
string encodedQuery = TitleFieldList;
string query = HttpUtility.UrlDecode(encodedQuery);
XDocument xmlQuery = XDocument.Parse(query);
if (xmlQuery.Element("query") != null)
{
Dictionary<string, string> nodesDictionary = new Dictionary<string, string>();
string root = xmlQuery.Element("query").Element("value").Value;
string value = xmlQuery.Element("query").Attribute("vf").Value;
string text = xmlQuery.Element("query").Attribute("tf").Value;
Item rootItem = SitecoreUtility.GetItemWithoutSecurity(new ID(root));
ChildList childList = rootItem.GetChildren();
foreach (Item child in childList)
{
string theValue = (value == "__ID") ? child.ID.ToString() : child.Fields[value].ToString();
string theText = child.Fields[text].ToString();
nodesDictionary.Add(theText, theValue);
}
titleDropDownList.DataSource = nodesDictionary;
titleDropDownList.DataTextField = "key";
titleDropDownList.DataValueField = "value";
titleDropDownList.DataBind();
}
and it works. The dropdownlist is populated with the correct data coming from the fields that were selected in the editor. I just can't believe that there is no easier way to do this. Plus how am I supposed to honor the MultipleSelectedValueField and the EmptyChoiceField if present?
Try to change the return type of your property and add attribute TypeConverter. The type specified in TypeConverter is responsible for converting raw string value to a property's return type.
ListItemCollectionConverter - is a converter provided by WFFM
[VisualProperty("My List Field:", 100)]
[VisualCategory("Appearance")]
[VisualFieldType(typeof(ListField))]
[TypeConverter(typeof(Sitecore.Form.Web.UI.Controls.ListItemCollectionConverter.ListItemCollectionConverter))]
public Sitecore.Form.Web.UI.Controls.ListItemCollection MyListField{
get { return myListField; }
set { myListField= value; }
}
I am trying to find a way to pass in an optional string list to a query. What I am trying to do is filter a list of tags by the relationship between them. For example if c# was selected my program would suggest only tags that appear in documents with a c# tag and then on the selection of the next, say SQL, the tags that are linked to docs for those two tags together would be shown, whittling it down so that the user can get closer and closer to his goal.
At the moment all I have is:
List<Tag> _tags = (from t in Tags
where t.allocateTagDoc.Count > 0
select t).ToList();
This is in a method that would be called repeatedly with the optional args as tags were selected.
I think I have been coming at it arse-backwards. If I make two(or more) queries one for each supplied tag, find the docs where they all appear together and then bring out all the tags that go with them... Or would that be too many hits on the db? Can I do it entirely through an entity context variable and just query the model?
Thanks again for any help!
You can try this.
First collect tag to search in a list of strings .
List<string> tagStrings = new List<string>{"c#", "sql"};
pass this list in your query, check whether it is empty or not, if empty, it will return all the tags, else tags which matches the tagStrings.
var _tags = (from t in Tags
where t.allocateTagDoc.Count > 0
&& (tagStrings.Count ==0 || tagStrings.Contains(t.tagName))
select t).ToList();
You can also try this, Dictionary represents ID of a document with it's tags:
Dictionary<int, string[]> documents =
new Dictionary<int, string[]>();
documents.Add(1, new string[] { "C#", "SQL", "EF" });
documents.Add(2, new string[] { "C#", "Interop" });
documents.Add(3, new string[] { "Javascript", "ASP.NET" });
documents.Add(4, new string[] { });
// returns tags belonging to documents with IDs 1, 2
string[] filterTags = new string[] { "C#" };
var relatedTags = GetRelatedTags(documents, filterTags);
Debug.WriteLine(string.Join(",", relatedTags));
// returns tags belonging to document with ID 1
filterTags = new string[] { "C#", "SQL" };
relatedTags = GetRelatedTags(documents, filterTags);
Debug.WriteLine(string.Join(",", relatedTags));
// returns tags belonging to all documents
// since no filtering tags are specified
filterTags = new string[] { };
relatedTags = GetRelatedTags(documents, filterTags);
Debug.WriteLine(string.Join(",", relatedTags));
public static string[] GetRelatedTags(
Dictionary<int, string[]> documents,
string[] filterTags)
{
var documentsWithFilterTags = documents.Where(o =>
filterTags
.Intersect(o.Value).Count() == filterTags.Length);
string[] relatedTags = new string[0];
foreach (string[] tags in documentsWithFilterTags.Select(o => o.Value))
relatedTags = relatedTags
.Concat(tags)
.Distinct()
.ToArray();
return relatedTags;
}
Thought I would pop back and share my solution which was completely different to what I first had in mind.
First I altered the database a little getting rid of a useless field in the allocateDocumentTag table which enabled me to use the entity framework model much more efficiently by allowing me to leave that table out and access it purely through the relationship between Tag and Document.
When I fill my form the first time I just display all the tags that have a relationship with a document. Using my search filter after that, when a Tag is selected in a checkedListBox the Document id's that are associated with that Tag(s) are returned and are then fed back to fill the used tag listbox.
public static List<Tag> fillUsed(List<int> docIds = null)
{
List<Tag> used = new List<Tag>();
if (docIds == null || docIds.Count() < 1)
{
used = (from t in frmFocus._context.Tags
where t.Documents.Count >= 1
select t).ToList();
}
else
{
used = (from t in frmFocus._context.Tags
where t.Documents.Any(d => docIds.Contains(d.id))
select t).ToList();
}
return used;
}
From there the tags feed into the doc search and vice versa. Hope this can help someone else, if the answer is unclear or you need more code then just leave a comment and I'll try and sort it.
I am trying to get the value from the Description field of a picklist in CRM, this is what I am using to get the Label value, how would I change it to get the Description Value?
RetrieveAttributeRequest request = new RetrieveAttributeRequest();
request.EntityLogicalName = "opportunity";
request.LogicalName = "country";
RetrieveAttributeResponse response = (RetrieveAttributeResponse)orgService.Execute(request);
PicklistAttributeMetadata picklist = (PicklistAttributeMetadata)response.AttributeMetadata;
foreach (OptionMetadata option in picklist.OptionSet.Options)
{
string picklistlabel = option.Label.UserLocalizedLabel.Label.ToString();
if (p.Column_16.ToString().ToUpper() == picklistlabel.ToString().ToUpper())
{
countryid= option.Value;
}
}
Thanks!
You can find the description for a specific option in a optionset by accessing the Description property.
Like this:
string description = option.Description.UserLocalizedLabel.Label.ToString();
Here is a list of members exposed by the PicklistAttributeMetadata.
I have table in my database names User with fields:
Id
FirstName
LastName
LoginName
Now I would like to present this table in ASPxGridView using LinqServerModeDataSource.
What I did is :
<dxdtlnq:LinqServerModeDataSource ID="LinqServerModeDataSource1" runat="server" OnSelecting="LinqServerModeDataSource1_OnSelecting"
ContextTypeName="MyContext" EnableDelete="True"
EnableInsert="True" EnableUpdate="True" TableName="Users" >
</dxdtlnq:LinqServerModeDataSource>
protected void LinqServerModeDataSource1_OnSelecting(object sender, LinqServerModeDataSourceSelectEventArgs e)
{
MyContext context = new MyContext();
var qry = from s in context.Users select s;
e.QueryableSource = qry;
}
That works great with my ASPxGridView. I can display data, insert and delete but now I would like to have additional column UserName which is FirstName + LastName.
So I did something like that:
Added appropriate column to my ASPxGridView (FieldName = "UserName")
and modified OnSelecting handler:
protected void LinqServerModeDataSource1_OnSelecting(object sender, LinqServerModeDataSourceSelectEventArgs e) {
KozuModelDataContext context = new MyContext();
var qry = (from s in context.Substitutions
select new
{
Id = s.Id,
FirstName = s.FirstName,
LastName = s.LastName,
LoginName = s.LoginName,
UserName = s.FirstName + " " + s.LastName,
}).AsQueryable();
e.KeyExpression = "Id";
e.QueryableSource = qry;
}
Now data in the grid is displayed buyt when I want to insert or edit data fields cannot be filled, textboxes doesnt respond in inserting form I cant type in any text.
Is there any solution for inserting and editing data in this manner ?
Thanks for help
I have tried to reproduce this issue and see this behavior. To be able to edit data using this approach, I suggest that you do the following:
1) Handle the ASPxGridView.CellEditorIntitialize event and set the e.Editor.ReadOnly property to false. This will allow the end-user to modify data in the EditForm editors;
2) Handle the ASPxGridView.RowUpdating (RowInserting) event and update data manually. Also, you should set the e.Cancel parameter to true (to prevent the grid from updating data itself) and also call the GridView's CancelEdit method to close the EditForm.
I should also mention that there is no need to fetch data for the UserName from the DB. This can be done using the ASPxGridView's CustomColumnDisplayText event handler:
protected void ASPxGridView1_CustomColumnDisplayText(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewColumnDisplayTextEventArgs e) {
if(e.Column.FieldName == "") {
object[] values = ASPxGridView1.GetRowValues(e.VisibleRowIndex, new string[] { "FirstName", "LastName" }) as object[];
e.DisplayText = values[0].ToString() + " " + values[1].ToString();
}
}
If this approach works for you, you can avoid using the Selecting event and thus set the LinqServerModeDataSource's TableName. This will allow you to provide the data editing feature not using the approach I explained above.