I am trying to select a column value in a selected row but I am unable to select the row. It seems that after clicking on the row to be selected, it does not go into the if statement. If I change the if statement to (dataItem.Selected = true) with only one "=", it goes in but returns the invoice id for all of the rows. Any advice on how to resolve this issue?
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
{
var a ="";
foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items)
{
if (dataItem.Selected == true)
{
a = dataItem.GetDataKeyValue("InvoiceId").ToString();
Response.Write(a);
}
}
}
Do you allow multiple selections or only just single selection in your RadGrid?
To me, the foreach loop code block doesn't seem correct if you do single row selection.
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
{
// get selected row
GridDataItem item =(GridDataItem)RadGrid1.SelectedItems[0];
}
Also, another point is you should set EnablePostBackOnRowClick property to true so that RadGrid's SelectedIndexChanged event will be fired properly on the server side.
<ClientSettings Selecting-AllowRowSelect="true" EnablePostBackOnRowClick="true">
</ClientSettings>
But if you wish to fire row select command from client side, then you should add a row click event with JS.
function RowClick(sender, eventArgs) {
sender.get_masterTableView().fireCommand("Select", eventArgs.get_itemIndexHierarchical());
}
Then associate that JS function to <ClientEvents OnRowClick="RowClick" /> in your aspx.
You can use RadGrid1.SelectedItems[0] To get your selected item.
protected void RadGrid1_ItemChanged(object sender, EventArgs e)
{
var myDataItem = RadGrid1.SelectedItems[0] as GridDataItem;
if (myDataItem != null)
{
var name = myDataItem ["InvoiceId"].Text;
}
}
And Woodykiddy is right. Check your postback and your allow row selecting.
And if you re using ajax dont forget the rad Ajax manager and panel.
Related
When navigating for one page to another does the value of the objects in the previous pages get lost? As I am navigating from page-1 to page-2 and then in page-2 I am calling a method which is in page-1 the values returned are null.
Why is this happening?
first page:
public Offer qw()
{
return off;
}
NavigationService.Navigate(new Uri("/Page1.xaml" ,UriKind.Relative));
page2:
var ob=obj.qw();
values in ob=null
if you are creating your obj field in your page2 means you are creating a new instance of the page1 so obviously it will differ from previous page.
so if you want to execute thi sfunctionality in page behind means you can do this in your page2
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
// NavigationEventArgs returns destination page
Page destinationPage = e.Content as Page2;
if (destinationPage != null)
{
// Change property of destination page
destinationPage.Page1=this;
}
}
This is bad logic for Windows Phone application. If you need to send some object from Page_1 to Page_N you should use PhoneApplicationService, if you send some simple object-type (numbers, strings, bools) you can use NavigationContext.
Sample PhoneApplicationService:
// Page_1 before navigate to Page_N
PhoneApplicationService.Current.State[key] = value; // key(string); value(any object)
// Page_N
object o;
PhoneApplicationService.Current.State.TryGetValue(key, out o)
// then do what you want with you object - o
Sample NavigationContext:
// Page_1 before navigate to Page_N
NavigationService.Navigate(new Uri("/SecondPage.xaml?msg=SomeMessageText", UriKind.Relative));
// Page_N
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string msg = "";
if (NavigationContext.QueryString.TryGetValue("msg", out msg))
string yourMessage = msg;
}
See MSDN:
NavigationContext
PhoneApplicationService and PhoneApplicationService samples
I download data from my server and use a DataGridView to present the result. When a new row is added, I’d like my program to show a signal. How can I do that?
Subscribe to the DataGridView.RowsAdded event.
dataGridView1.RowsAdded += new DataGridViewRowsAddedEventHandler(dataGridView1_RowsAdded);
void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
// show the signal
}
You need to use userAddedRow event , when activate that event you can use it to send
boolean like true or false like this Example
private void usersDGV_UserAddedRow(object sender, DataGridViewRowEventArgs e)
{
//this event occurs when user added new row to the datagridview
//and will turn the boolean newRowAdded on.
newRowAdded = true;
}
I am trying to delete a MenuItem from a LongListSelector in my Windows Phone 8 app. The MenuItems play various sounds when clicked and I want the user to be able to delete them.
There are two panels on the app. The second panel records a new sound and puts the recording on the LongListSelector as a new MenuItem.
Problem: After I do the delete the display looks exactly the same and the sound still plays! However, if I record a new sound (switching to the new recording panel) then the deletion works with the deleted MenuItem gone.
How do I force the update/refresh of the LongListSelector to unload/delete the MenuItem and associated sound data resident on the GUI?
The following code is called from from the MenuItem's click event. The LongListSelector is named 'CustomSounds':
private void DeleteSoundClick(object sender, RoutedEventArgs e)
{
var menuItem = sender as MenuItem;
if (menuItem == null) return;
var soundData = menuItem.DataContext as SoundData;
if (soundData == null) return;
if (soundData.FilePath.Contains(CustomSounds.Name))
{
CustomSounds.ItemsSource.Remove(soundData);
}
this.LayoutRoot.UpdateLayout();
}
Inverse your thing. Set item source with new list.
private void DeleteSoundClick(object sender, RoutedEventArgs e)
{
var menuItem = sender as MenuItem;
if (menuItem == null) return;
var soundData = menuItem.DataContext as SoundData;
if (soundData == null) return;
if (soundData.FilePath.Contains(CustomSounds.Name))
{
MyNewList.remove(soundData);
CustomSounds.ItemsSource = myNewList;
}
this.LayoutRoot.UpdateLayout();
}
Create local variable and set your itemsource in constructor.
Other thing :
create an updated list :
private ObservableCollection<Sound> _myNewList;
public ObservableCollection<Sound> MynewList{
get
{
return _myNewList;
}
set
{
_myNewList= value;
RaisePropertyChanged(MynewList);
}
Bind this in your listbox :
<listbox itemSource="{Binding MyNewList" SelectedItem="{Binding SelectedSound,mode=twoway}>
Create selectedSound:
private Sound _selectedSound;
public Sound SelectedSound{
get
{
return _selectedSound;
}
set
{
_selectedSound= value;
RaisePropertyChanged(SelectedSound);
}
Delete item :
private void DeleteSoundClick(object sender, RoutedEventArgs e)
{
if(SelectedSound != null){
Mynewlist.remove(SelectedSound);
}
}
:D
ObservableCollection is nothing more than a collection with notification that when something is changed in the collection, it lets the UI know. It's just a ItemSource, so your LongListSelector is populated by the OC...
I had the same issue, however, I used simple List.
Solution was easy - just created new object of the List
var newList = new List<TheModel>();
newList.AddRange(originalList);
TheLongListSelector.ItemsSource = newList;
TheLongListSelector.UpdateLayout();
originalList was list with removed item.
It's not the most efficient way, but it works. I think that's no problem for small data.
I have a navigation controller to show a list o item on table, then I need to touch an item a show the details of this item.
Here it's my code of how a fill the table:
public void SearchHotel (){
Hotel hotel = new Hotel();
var distribution = new HotelDistribution[]{new HotelDistribution(){ Adults = 1, Children = 0, ChildrenAges = new int[0]} };
var items = hotel.SearchHotels(Convert.ToDateTime("2013-08-08"),Convert.ToDateTime("2013-09-09 "),"(MIA)", distribution,"","","",0);
data = new List<DtoHotelinformation>();
foreach (var item in items)
{
DtoHotelinformation DtoHotelinformation = new DtoHotelinformation();
DtoHotelinformation.code = item.Code.ToString();
DtoHotelinformation.price = item.Price.ToString();
DtoHotelinformation.title = item.Name.ToString().ToTitleCase();
DtoHotelinformation.subtitle = item.Address.ToString();
DtoHotelinformation.rating = item.Rating.ToString();
DtoHotelinformation.imageUlr = item.ImageUrl;
data.Add(DtoHotelinformation);
}
hud.Hide(true);
hud.RemoveFromSuperview();
HotelSearchTable.Source = new HotelTableSource(data.ToArray());
HotelSearchTable.ReloadData();
}
Because I'm using storyboard to show the details view controller I have this code on my table source:
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
if (RowTouched != null) {
RowTouched (this, EventArgs.Empty);
}
tableView.DeselectRow (indexPath, true); // normal iOS behaviour is to remove the blue highlight
}
Back in to my viewcontroller I call the RowTouched to show the details controller like this:
public override void ViewDidAppear (bool animated) {
base.ViewDidAppear (animated);
SearchHotel ();
var source = new HotelTableSource(data.ToArray());
var detail = Storyboard.InstantiateViewController("HotelDetailScreen") as iPhoneHotelDetailViewController;
source.RowTouched += (sender, e) => {
this.NavigationController.PushViewController(detail, true);
};
HotelSearchTable.Source = source;
}
But I need to pass the information of the item touched on the table to show the details. I don't really don't know what do I have to do?
NOTE: I can't use PrepareForSegue because I don't have a segue between controllers.
Thanks in advance
If you want you can get a hold of your UINavigationController
from within your Row Selected event, inside of your Table Data Source.
From there you can push your new ViewController.
[indexPath.Row] in "Row_Selected" should tell you which element in your array or list, that the user has selected.
UINavigationController navcontroller =(UINavigationController)UIApplication.SharedApplication.Windows[0].RootViewController;
Passing data to an event handler is exatly what the EventArgs parameter is for.
Create a class that inherits from EventArgs and has properties for the data you need:
public class HotelSelectedEventARgs : EventArgs
{
public DTOHotelInformation HotelInfo { get; set; }
}
Then, when you call your handler in RowSelected, instead of passing an empty EventArgs, create an instance of your custom class and assign the selected data to the HotelInfo property.
Situation:
I'm writing a program in which the user clicks a button to create tabs in a TabControl. The user has created 5 tabs and then wants to delet Tab 3. This leaves tabs 1, 2, 4 and 5.
How can I re-order the tabs to fill the gap (Tab 4 becomes the new Tab 3, Tab 5 becomes Tab 4, etc.)? Does the TabControl have a built-in function for this?
refer to linke : MSDN Add And Remove Tab From Tabcontrol
// Removes the selected tab:
tabControl1.TabPages.Remove(tabControl1.SelectedTab);
// Removes all the tabs:
tabControl1.TabPages.Clear();
if you want remove tab by index
tabControl1.TabPages.RemoveAt(i);
use a Tabpage Array that is collection of all tabpages , Search in TabPage array by TabControl.SelecetedIndex , to find Index of TabPage After Deletion then you can do anything this means that you just delete Tabpage from TabControl , but not from TabPage Array and when need one of them search in TabControl.you can relate Selected Tabpage to Tabpage array by set Tag Property to Real Index of Array.
use this 2 function :
TabPage[] tabPages;
private void MyForm_Load(object sender, EventArgs e)
{
tabPages = new TabPage[tabServices.TabPages.Count];
for (int i = 0; i < tabServices.TabPages.Count; i++)
{
tabServices.TabPages[i].Tag=i;//for relation between TabControl and Array
tabPages[i] = tabServices.TabPages[i];
}
}
private int GetTabIndex(TabPage pg)
{
return int.Parse(tabServices.TabPages[tabServices.SelectedIndex].Tag.ToString());
}
private TABPAGE GetTABPAGE(TabPage pg)
{
return (TABPAGE)int.Parse(tabServices.TabPages[tabServices.SelectedIndex].Tag.ToString());
}
private void tabServices_SelectedIndexChanged(object sender, EventArgs e)
{
switch (GetTABPAGE(tabServices.TabPages[tabServices.SelectedIndex]))
{
case TABPAGE.TabP1:
//Do Works;
break;
case TABPAGE.TabP2:
//Do Works;
break;
case TABPAGE.TabP3:
//Do Works;
break;
case TABPAGE.TabP4:
//Do Works;
break;
}
}
and define an Enum for All TabPages (for ReadAbility and Index to Tabpage meaningful name ):
public enum TABPAGE { TabP1 = 0, TabP2 = 1, TabP3 = 2};