I have a AspxGridView and when i double click to a row, it shows a modal window. What i want to do is, send one columns' value to a AspxLabel which is at ModalWindow. But i couldn't manage to do it, in gridview i use ClientSideEvents RowDblClick to get row value. Here is the code:
GridView:
<dxwgv:ASPxGridView ID="gw_Parameters" runat="server"
CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua"
AutoGenerateColumns="False" ClientInstanceName="grid"
OnCustomDataCallback="gw_Parameters_CustomDataCallback">
<ClientSideEvents RowDblClick="function(s, e) {
grid.GetValuesOnCustomCallback(e.visibleIndex, ShowModalWindow())
}" />
Script:
function ShowModalWindow(val)
{
pcc_Question.Show();
lblCQuestionText.SetText(val);
}
And c#:
protected void gw_Parameters_CustomDataCallback(object sender, ASPxGridViewCustomDataCallbackEventArgs e)
{
int visibleIndex = Convert.ToInt32(e.Parameters);
string fieldName = string.Empty;
if (gw_Parameters.VisibleColumns[0] is GridViewCommandColumn)
fieldName = ((GridViewDataColumn)gw_Parameters.VisibleColumns[3]).FieldName;
else
fieldName = ((GridViewDataColumn)gw_Parameters.VisibleColumns[2]).FieldName;
e.Result = gw_Parameters.GetRowValues(visibleIndex, fieldName);
}
Thanks for the help,
Mehmet Şerif Tozlu
Your code looks correct and should work. I suggest that you set the breakpoint in the gw_Parameters_CustomDataCallback method and check the e.Result value. Also, according to your code, the lblCQuestionText is the ClientInstanceName property of the label residing in the PopupControl. Is it true?
Mehmet,
Try the results here which has several examples.
Related
So, I have a listview and I want it whenever an item is created to scroll to that item (bottom). Because I am using MVVM I found really nice explanation on how to make a new control that inherits from listview that scrolls down. The problem is that this answer (the third) is referring to WPF 6 years ago.
I am making a UWP app, so I copied the code and tried to format it to my needs. The following code doesn't give any error or exception but instead it loads the "ChatListView" as I call it perfectly and then does nothing. The comments are only a bit edited compared to the original code.
What can I do ? Thank you in advance!
public class ChatListView : ListView
{
//Define the AutoScroll property. If enabled, causes the ListBox to scroll to
//the last item whenever a new item is added.
public static readonly DependencyProperty AutoScrollProperty =
DependencyProperty.Register(
"AutoScroll",
typeof(Boolean),
typeof(ChatListView),
new PropertyMetadata(
true, //Default value.
new PropertyChangedCallback(AutoScroll_PropertyChanged)));
//Gets or sets whether or not the list should scroll to the last item
//when a new item is added.
public bool AutoScroll
{
get { return (bool)GetValue(AutoScrollProperty); }
set { SetValue(AutoScrollProperty, value); }
}
//Event handler for when the AutoScroll property is changed.
//This delegates the call to SubscribeToAutoScroll_ItemsCollectionChanged().
//d = The DependencyObject whose property was changed.</param>
//e = Change event args.</param>
private static void AutoScroll_PropertyChanged(
DependencyObject d, DependencyPropertyChangedEventArgs e)
{
SubscribeToAutoScroll_ItemsCollectionChanged(
(ChatListView)d,
(bool)e.NewValue);
}
//Subscribes to the list items' collection changed event if AutoScroll is enabled.
//Otherwise, it unsubscribes from that event.
//For this to work, the underlying list must implement INotifyCollectionChanged.
//
//(This function was only creative for brevity)
//listBox = The list box containing the items collection.
//subscribe = Subscribe to the collection changed event?
private static void SubscribeToAutoScroll_ItemsCollectionChanged(
ChatListView listView, bool subscribe)
{
INotifyCollectionChanged notifyCollection =
listView as INotifyCollectionChanged;
if (notifyCollection != null)
{
if (subscribe)
{
//AutoScroll is turned on, subscribe to collection changed events.
notifyCollection.CollectionChanged +=
listView.AutoScroll_ItemsCollectionChanged;
}
else
{
//AutoScroll is turned off, unsubscribe from collection changed events.
notifyCollection.CollectionChanged -=
listView.AutoScroll_ItemsCollectionChanged;
}
}
}
//Event handler called only when the ItemCollection changes
//and if AutoScroll is enabled.
//sender = The ItemCollection.
//e = Change event args.
private void AutoScroll_ItemsCollectionChanged(
object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
int count = Items.Count;
ScrollIntoView(Items[count - 1]);
}
}
//Constructor a new ChatListView.
public ChatListView()
{
//Subscribe to the AutoScroll property's items collection
//changed handler by default if AutoScroll is enabled by default.
SubscribeToAutoScroll_ItemsCollectionChanged(
this, (bool)AutoScrollProperty.GetMetadata(typeof(ChatListView)).DefaultValue);
}
}
If you want to create a chat application you can use the ItemsStackPanel's ItemsUpdatingScrollMode particular property to KeepLastItemInView value to scroll to the latest item.
Usage:
<ListView>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsStackPanel ItemsUpdatingScrollMode="KeepLastItemInView" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
Note: KeepLastItemInView enum member was introduced in the 14393 SDK.
Related link:
https://learn.microsoft.com/en-us/uwp/api/Windows.UI.Xaml.Controls.ItemsStackPanel#properties_
The accepted answer is pretty nice. However I there is one thing it won't do (at least if I simply copy and paste the above XAML): it won't do its intended scrolling if, say, the user was away from that page while new items were added, and then they navigated to the page.
For that I had to hook into
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (MyListView.Items.Count == 0)
return;
object lastItem = MyListView.Items[MyListView.Items.Count - 1];
MyListView.ScrollIntoView(lastItem);
}
I have a user control, I want to make if conditions in the ascx, and upon that call a function in the user control and return data from the method to be displayed as html in the ascx. Any ideas? I am still newbie to asp.
Just drop a literal onto your user control. Then in your code behind, it'll look something like this:
private void Page_Load(object sender, System.EventArgs e)
{
// Make your IF conditions here
MyFunction();
}
private void MyFunction()
{
string myHtml = "<div>My Html Code!</div>";
literal1.Text = myHtml;
}
That should render your HTML.
I'm hoping someone can help me. I have searched the web for a suitable answer but haven't found one.
I have the following LinkButton in a GridView (GridView2) which is within an UpdatePanel set to UpdateMode='Conditional':
<ItemTemplate>
<asp:LinkButton ID="lblSCcomments" runat="server" Width="80"
Text='<%#Eval("ShortCode")%>' CommandName="hyperSC"
OnCommand="GridView2_Command"
CommandArgument='<%#Eval("ShortCode")%>'/>
</ItemTemplate>
with this code behind:
protected void GridView2_Command(object sender, CommandEventArgs e)
{
if (e.CommandName == "hyperSC")
{
string sc = e.CommandArgument.ToString();
lblShortCode.Text = sc;
Session["scode"] = sc;
Server.Transfer("~/MemberPages/reviews.aspx");
}
}
Unfortunately, when I click on the link the command is not firing. But this was working outside of the UpdatePanel. I don't need the Gridview to refresh, just need to populate the Session variable and lblShortCode Label with the selected row Shortcode and be redirected to another page.
You have to add OnRowCommand event in your GridView like <asp:GridView ID="GridView2" runat="server" OnRowCommand="GridView2_RowCommand"> and do you .CS code in this event:
protected void GridView2_RowCommand(object sender, CommandEventArgs e)
{
if (e.CommandName == "hyperSC")
{
string sc = e.CommandArgument.ToString();
lblShortCode.Text = sc;
Session["scode"] = sc;
Server.Transfer("~/MemberPages/reviews.aspx");
}
}
And remove the OnCommand event from LinkButton.
I have a bunch of TextBox-es generated dynamically. At the step of creation I'm assigning the ID property for them.
e.g.
id = ...
Button b = new Button();
b.setText("add textbox");
b.addClickHandler(new Clickhandler() {
Textbox tb = new TextBox();
tb.getElement().setId(Integer.toString(id));
tb.setText("some text");
}
id += 1;
I need to access them later by their IDs, but I cannot do it.
I tried to use the DOM object in order to get a widget, but it produces an exception:
String id = "some id";
Element el = DOM.getElementById(id);
String value = el.getAttribute("value"); - this line produces an exception.
I've also tried to use el.getInnerText, el.getNodeValue - no luck. I have see in the chrome debugger - the textboxes don't have the 'value' property.
you can get the widget associated to an element this way:
public static IsWidget getWidget(com.google.gwt.dom.client.Element element) {
EventListener listener = DOM
.getEventListener((com.google.gwt.dom.client.Element) element);
// No listener attached to the element, so no widget exist for this
// element
if (listener == null) {
return null;
}
if (listener instanceof Widget) {
// GWT uses the widget as event listener
return (Widget) listener;
}
return null;
}
Since you are constructing your textboxes in gwt java code, why not put them into a map and access them later?
One thing to keep in mind is the difference between an attribute and a property in HTML/DOM. In your example, "value" is a property. You could try Element#getPropertyString. It used to be that attributes and properties were used interchangeably, but in modern browsers that's no longer the case.
GWT's CellBrowser is a great way of presenting dynamic data.
However when the browser contains more rows than some (seemingly) arbitrary maximum, it offers a "Show More" label that the user can click to fetch the unseen rows.
How can I disable this behavior, and force it to always show every row?
There are several ways of getting rid of the "Show More" (which you can combine):
In your TreeViewModel, in your NodeInfo's setDisplay or in the DataProvider your give to the DefaultNodeInfo, in onRangeChange: overwrite the display's visible range to the size of your data.
Extend CellBrowser and override its createPager method to return null. It won't change the list's page size though, but you can set it to some very high value there too.
The below CellBrowser removes the "Show More" text plus loads all available elements without paging.
public class ShowAllElementsCellBrowser extends CellBrowser {
public ShowAllElementsCellBrowser(TreeViewModel viewModel, CellBrowser.Resources resources) {
super(viewModel, null, resources);
}
#Override
protected <C> Widget createPager(HasData<C> display) {
PageSizePager pager = new PageSizePager(Integer.MAX_VALUE);
// removes the text "Show More" during loading
display.setRowCount(0);
// increase the visible range so that no one ever needs to page
display.setVisibleRange(0, Integer.MAX_VALUE);
pager.setDisplay(display);
return pager;
}
}
I found a valid and simple solution in setting page size to the CellBrowser's builder.
Hope this will help.
CellBrowser.Builder<AClass> cellBuilder = new CellBrowser.Builder<AClass>(myModel, null);
cellBuilder.pageSize(Integer.MAX_VALUE);
cellBrowser = cellBuilder.build();
The easiest way to do this is by using the:
cellTree.setDefaultNodeSize(Integer.MAX_VALUE);
method on your Cell Tree. You must do this before you begin expanding the tree.
My workaround is to navigate through elements of treeview dom to get "show more" element with
public static List<Element> findElements(Element element) {
ArrayList<Element> result = new ArrayList<Element>();
findShowMore(result, element); return result; }
private static void findShowMore(ArrayList res, Element element) {
String c;
if (element == null) { return; }
if (element.getInnerText().equals("Show more")) { res.add(element);
}
for (int i = 0; i < DOM.getChildCount(element); i++) { Element
child = DOM.getChild(element, i); findShowMore(res, child); } }
and than use:
if (show) { element.getStyle().clearDisplay(); } else {
element.getStyle().setDisplay(Display.NONE); }