Telerik Radgrid Access Values - telerik

I want to access values of the insert form in Telerik radgrid. how can i do that this is what i am trying
protected void RadGrid3_InsertCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.PerformInsertCommandName)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
string a = (editedItem.FindControl("ID") as TextBox).Text;
string b = (editedItem.FindControl("Quantity") as TextBox).Text;
}
}
It throws me the following error
Object reference not set to an instance of an object.

When editing or inserting a grid item, you could access and modify the controls generated in the editable item (reference Telerik documentation).
Try something like this:
protected void RadGrid3_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem editableItem = e.Item as GridEditableItem;
string a= editableItem["Id"].Controls[0] as TextBox;
string b= editableItem["Quantity"].Controls[0] as TextBox;
}
}
Please note that I have not tested the the above snippet. For more references you can look here

Related

xamarin forms syncfusion ListView ItemAppearing

I use syncfusion listview to create listview on xamarin forms
I want to use the ItemAppearing option in listview
I used this EXAMPLE on website:https://help.syncfusion.com/cr/cref_files/xamarin/Syncfusion.SfListView.XForms~Syncfusion.ListView.XForms.SfListView.html
and this EXAMPLE: https://help.syncfusion.com/cr/cref_files/xamarin/Syncfusion.SfListView.XForms~Syncfusion.ListView.XForms.SfListView~ItemAppearing_EV.html#ExampleBookmark
I use this example and found this problem
ListView.ItemAppearing +=listView_ItemAppearing;
public void listView_ItemAppearing(object sender, Syncfusion.ListView.XForms.ItemAppearingEventArgs e)
{
var temp= e.ItemData as IEnumerable<ListViewCall>;
//temp.ToList();
}
I cast e.ItemData to List<ListViewCall> and get null
e.ItemData has data but var temp is null
Why would this be?
ItemData :Gets the underlying data object of the ListViewItem when item appearing from the bound data source.
so e.ItemData will return you the binding object. like the example above,it will return the object BookInfo.
public void listView_ItemAppearing(object sender, Syncfusion.ListView.XForms.ItemAppearingEventArgs e)
{
var temp= e.ItemData as BookInfo;
}
public void listView_ItemAppearing(object sender, Syncfusion.ListView.XForms.ItemAppearingEventArgs e)
{
if (e.ItemData is GroupResult)
{
var listViewCalls = (e.ItemData as GroupResult).Items as EnumerableQuery<ListViewCall>;
foreach (var listViewCall in listViewCalls)
{
}
}
else if (e.ItemData is ListViewCall)
{
var listViewCall = e.ItemData as ListViewCall;
}
// foreach (Object obj in e.ItemData.GetType().GetProperties(System.Reflection.BindingFlags.Public | BindingFlags.Instance))
// {
// string s = (obj as Call).Title;
//}
}

How to delete the listbox item in wp7?

Listbox having 2 buttons.When click on button need to delete the item from that listbox.
please tell me how to acheive that?
List<SampleCheckedData> interestrates = new List<SampleCheckedData>();
interestrates = (from rts in xmlDocu.Descendants("Friend")
select new SampleCheckedData
{
Id = (string)rts.Element("userid"),
Name = (string)rts.Element("name"),
Icon = (string)rts.Element("imageurl"),
VisibleStatus = (string)rts.Element("visiblestatus"),
AppStatus = (string)rts.Element("loginstatus"),
imgBubble =bitmapRed,
}).ToList<SampleCheckedData>();
this.lstImages.ItemsSource = interestrates;
private void btnAccept_MouseEnter(object sender, MouseEventArgs e)
{
int _id = int.Parse(((System.Windows.FrameworkElement)(e.OriginalSource)).Tag.ToString());
lstFriendRequuest.Items.RemoveAt(lstFriendRequuest.SelectedIndex);
}
To delete the selected item,
listbox.Items.RemoveAt(listbox.SelectedIndex);
Make your collection available globally on this page, and now you can manipulate on it easily from btnAccept_MouseEnter event:
public interestrates;
...
{
interestrates = ...
this.lstImages.ItemsSource = interestrates;
}
private void btnAccept_MouseEnter(object sender, MouseEventArgs e)
{
interestrates.RemoveAt(lstFriendRequuest.SelectedIndex);
}
Also, make sure that a click on a ListBox item changes SelectedIndex accordingly

Unable to show the selected item in the Wp7 Listpicker control

Basically i am trying to pull the contacts from the phone and showing them in the Listpicker control for a feature in my app. I have two Listpickers, one for name of contacts list and the other showing the list of phonenumbers for the chosen contact.
Here is my code:
//Declarations
ContactsSearchEventArgs e1;
String SelectedName;
String SelectedNumber;
List<string> contacts = new List<string>();
List<string> phnum = new List<string>();
public AddressBook() // Constructor
{
InitializeComponent();
Contacts contacts = new Contacts();
contacts.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(contacts_SearchCompleted);
contacts.SearchAsync(string.Empty,FilterKind.None,null);
}
void contacts_SearchCompleted(object sender, ContactsSearchEventArgs e)
{
e1 = e;
foreach (var result in e.Results)
{
if (result.PhoneNumbers.Count() != 0)
{
contacts.Add(result.DisplayName.ToString());
}
}
Namelist.ItemsSource = contacts;
}
private void Namelist_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SelectedName = (sender as ListPicker).SelectedItem.ToString();
phnum.Clear();
foreach (var result in e1.Results)
{
if (SelectedName == result.DisplayName)
{
phnum.Add(result.PhoneNumbers.FirstOrDefault().ToString());
}
}
Numbers.ItemsSource = phnum;
}
private void Numbers_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SelectedNumber = (sender as ListPicker).SelectedItem.ToString();
}
Am able to populate the Numberlist with phonenumbers for the chosen name at the Listpicker background, but the number is not showing up in the front. I think Numbers_SelectionChanged() event is called only one time when the page loads and am not seeing it triggerd when i change the contact list. Anyone has an idea of where am going wrong ?
If you change
List<string>
To
ObservableCollection<string>
this should work.
Also then you only need to set the ItemSource once, in Xaml or you constructor.
But you may run into another issue with the November 2011 Toolkit and ListPicker.
See more in thread.
private void Namelist_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SelectedName = (sender as ListPicker).SelectedItem.ToString();
phnum = new List<string>(); // Changed instead of phnum.Clear()
foreach (var result in e1.Results)
{
if (SelectedName == result.DisplayName)
{
phnum.Add(result.PhoneNumbers.FirstOrDefault().ToString());
}
}
Numbers.ItemsSource = phnum;
}
This works !!. While debugging i found its phnum.Clear() giving a problem. So i thought to create a new instance of phnum list for selected contact.

Cant get selected listboxitem to show on my detail page

I have made and rss reader and have a listbox with all the feeds in it. When I select one item and want to see the whole article I only get the selectedindex number, 0,1,2 and so on.
Here is my code:
private void feedListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListBox listBox = sender as ListBox;
if (listBox != null && listBox.SelectedItem != null)
{
NavigationService.Navigate(new Uri("/DetailsPage.xaml?feeditem=" + listBox.SelectedIndex, UriKind.Relative));
}
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string feeditem = "";
if (NavigationContext.QueryString.TryGetValue("feeditem", out feeditem))
{
this.textBlock1.Text = feeditem;
}
}
What am I missing here?

How to format radgrid cell programmatically

I have to format (backcolor, forecolor, font style) a radgrid's cells depending on the value of the cell.
For example
If the value is negative set the fore color of that cell as red.
Can any one please tell me how this can be achieved?
protected void grdName_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
if (Convert.ToInt32(((DataRowView)item.DataItem)["Column"]) < value)
{
TableCell cell = item["Column"];
cell.BackColor = Color.PeachPuff;
}
}
}
Add the line onItemDataBound="Data_OnitemDataBound" to your radGrid declaration in your aspx page.
Then add this to your code behind. The number in the Cells[] is the index of the column you want to modify or validate against.
protected void Data_OnItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
if (Convert.ToDecimal(item.Cells[3].Text) < 0)
{
item.Cells[3].ForeColor = System.Drawing.Color.Red;
}
}
}
Below code can be used for all the cells in the RadGrid.
protected void RadGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
foreach (GridDataItem dataItem in RadGridProduct.MasterTableView.Items)
{
int cellCount = dataItem.Cells.Count;
foreach (GridTableCell item in dataItem.Cells)
{
if (item.Text == null ||Convert.ToInt32(item.Text) < 0 )
item.BackColor = System.Drawing.Color.Brown;
}
}
}

Resources