Telerik RadGrid- Access Items' GroupFooter - c#

I'm trying to write content to an items' Group Footer on an item's ItemDataBound event.
Anyone have any idea how to access an Item's group footer from the Item itself?
In other words, how would I get an item's associated group footer from the item object as it's being bound?
protected void grid_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
**GridItemGroupFooter footer = item.GroupFooter** <-- Pseudocode for what I want to do
}
}

you should do it like this
if (e.Item is GridFooterItem)
{
itemtype somenameforitem=(itemtype )grid.FooterRow.FindControl("youritemid");
//for ex if you need textbox then it will be like this
//TextBox texte=(TextBox)gridname.FooterRow.FindControl("textboxid");
}
also you can do it like this.
GridFooterItem footerItem = (GridFooterItem)grid.MasterTableView.GetItems(GridItemType.Footer)[0];
TextBox texte=(TextBox)footerItem.FindControl("textboxid");//accessing Button inside FooterTemplate
I have give the index [0] while getting the grid footer item as the text box is one and only item in my grid footer, if you have multiple footer items, you can give the index of the item you wan to find

Related

Name of item in ListView

I am trying to get name of clicked item in ListView. I do not declaring in code names of items in ListView. User is declaring that names in running app. What i need to do is, when i click on item in ListView, in TextBlock will be name of item, whitch i clicked.
This is my simple code yet:
private void lstViewOfUsers_ItemClick(object sender, ItemClickEventArgs e)
{
TextBlock.Text = Name of clicked item
}
To get the text of an item in the first column then you would do :
TextBlock.Text = lstViewOfUsers.SelectedItems[0].Text;
If you wanted to get the text of a subitem it would look like this :
TextBlock.Text = lstViewOfUsers.SelectedItems[0].SubItems[1].Text;
You can get the index of the clicked item by using the ItemClickEventArgs parameter
another option is to do something like this:
MyItemModel item = (MyItemModel)e.ClickedItem;

Using mouse click event to get ListViewItem text

I want to use listview to populate it with data and then use mouseclick event to fill some textboxes with data. I looked up an example in msdn:
ListViewItem theClickedOne = listView1.GetItemAt(e.X, e.Y);
ListViewItem theClickedtwo = listView1.FocusedItem;
if (theClickedOne != null)
{
MessageBox.Show(theClickedtwo.ToString());
//do your thing here.
//there is a reference to the listview item we clicked on
//in our theClickedOne variable.
}
but I couldn't think about a way to use it in order to differentiate the listviewitems I use since the fist Column in my program is the same and it will only give me a string with it's name(first Column).I want to have something similar to next example but for treeview.
void treeView1_NodeMouseClick(Object sender, TreeNodeMouseClickEventArgs e)
{
MessageBox.Show(e.Node.Text);
}
When populating you ListView, set the Tag property of the items, e.g.
newItem.Tag = "Item 1";
The Tag property has type object, so you can use anything you want here to identify the item. When handling the mouse click event simply check the Tag value again:
if((string)(clickedItem.Tag) == "Item 1")
{
// do stuff for this specific item.
}

How do I change a ListView dynamically on DataBound?

I have a ListView with a template, it puts a bunch of data in, like X Y Z.
I want to hide show some columns based on criteria, so I have ItemDataBound event, but I don't know how to get the actual listview row so I can do things to do it.
Any ideas?
You can access the ListViewItemEventArgs' Item property to get at the current item (the one being bound to data).
The sample code below (which shows how to customize a ListView item in the ItemDataBound event) was taken from the MSDN documentation:
protected void ContactsListView_ItemDataBound(object sender, ListViewItemEventArgs e)
{
Label EmailAddressLabel;
if (e.Item.ItemType == ListViewItemType.DataItem)
{
// Display the e-mail address in italics.
EmailAddressLabel = (Label)e.Item.FindControl("EmailAddressLabel");
EmailAddressLabel.Font.Italic = true;
System.Data.DataRowView rowView = e.Item.DataItem as System.Data.DataRowView;
string currentEmailAddress = rowView["EmailAddress"].ToString();
if (currentEmailAddress == "orlando0#adventure-works.com")
{
EmailAddressLabel.Font.Bold = true;
}
}
}

Insert new item to ListView after first item

I am trying to add a new item in a ListView on itemdatabound. What is the best way to do it?
Data comes from a dataset with
TopicReplyListView.DataSource = TopicReplyDataTable;
TopicReplyListView.DataBind();
on
TopicReply_ItemDataBoundEvent
I want to add text such as "TEST ITEM" and continue to bind
my TopicReply_ItemDataBoundEvent is
protected void TopicReply_ItemDataBoundEvent(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
ListViewDataItem dataItem = (ListViewDataItem)e.Item;
}
}
Where are you actually trying to add the "Test Item" text?
If you need to add an item to the data source then just do that in the data table before assigning it to the datasource.
If you need to change something in the ItemTemplate then maybe use the ItemCreated event on the list view.

Change a selected item in a listview based on the selection in another listview

I have two list views. In the Item command event of the first Listview i am showing the second list view in modal popup using ajaxtoolkit.
protected void lvSelection_ItemCommand(object sender, ListViewCommandEventArgs e)
{
this.lvPopup.Visible = true;
this.lvPopup.DataSource = linqdataSource;
this.lvPopup.DataBind();
this.mdlPopup.Show();
}
Now in the itemcommand event of the second list view I need to change the content of the selected item in the first listview.
Is it possible to do that?
protected void lvPopup_ItemCommand(object sender, ListViewCommandEventArgs e)
{
// Set the text of the first list view item to the selected item
// of the second list view.
lstView1.Items[lstView1.SelectedIndex].Text =
lstView2.Items[lstView2.SelectedIndex].Text
}
I'd think that if you were to set the CommandName of the selector button in the first ListView to "Select" - from the second list view's ItemCommand event, you should be able to alter either the SelectedItemTemplate or the current item for the selected item in the first list.
protected void lvPopup_ItemCommand(object sender, ListViewCommandEventArgs e)
{
lvSelection.SelectedItemTemplate = "<div>woohoo!</div>";
// OR...
lvSelection.Items[lvSelection.SelectedIndex].SkinID = "SomeNewSkinForExample";
mdlPopup.Hide();
}
Have you already tried to dynamically generate the items of the List?
On the event code of the 1st list, clear the Items from the 2nd list and populate it with whatever logic suits you.

Categories

Resources