autocompleteextender Null value after setting innerHtml - c#

I have an autocompleteextender which works very fine when i set its innerHtml to text received from the webservice a i can catch the selected value of that text on selectedItem function . but when i set some HTML elements inside innerHtml of the childnode i loss the value of that node on selectedItem function (to keep on mind that i can see set value on OnClientPopulated function !).
here is OnClientPopulated
function PopulateDataForAce_Locations(sender) {
$("#tbxLocation").css("background-image", "none");
var comletionList = $find("aceYer").get_completionList();
for (var i = 0; i < comletionList.childNodes.length; i++) {
var data = JSON.parse(comletionList.childNodes[i].innerText);
var image = data[0];
var imageClass = "";
var textClass = "";
if (data[1].indexOf("##") > -1 || comletionList.childNodes[i]._value == "0000") {
imageClass = "imageStyleIlce";
textClass = "textStyleIlce";
}
else {
imageClass = "imageStyleIl";
textClass = "textStyleIl";
}
var text = data[1].replace("##", "");
var text2 = data[2];
// comletionList.childNodes[i].innerHTML = "<font class=\"" + textClass + "\">" + text + "</font>";
comletionList.childNodes[i].innerHTML = text;
}
}
when i use the comment line i lose the value of the node.
any help is appreciated

the only way that i found to get the value on selected item function was
function aceLocation_itemSelected(sender, e) {
var index = $find("aceYer")._selectIndex;
var _item = $find("aceYer").get_completionList().childNodes[index];
var hfYer = $get('<%= hfYer.ClientID %>');
hfYer.value = _item._value;
}
while e.get_value() did not work with html item.

Related

GeckoFX Source Get DOM / hidden div elements

I am trying to replace the inner HTML of a specific div. Which shows up through the Gecko browser and view-source, but when the collection of elements is sent to a text box, the div is nowhere to be found. Here are some of the methods I have tried.. Any help is greatly appreciated..
//NODES
GeckoNodeCollection nodes2 = mainbrowser.Document.GetElementsByClassName("*");
foreach (GeckoNode node in nodes2)
{
GeckoElement element3 = node as GeckoElement;
}
GeckoNodeCollection nod = mainbrowser.Document.GetElementsByClassName("minin-class");
foreach (GeckoNode node in nod)
{
if (NodeType.Element == node.NodeType)
{
try
{
GeckoElement ele = (GeckoElement)node;
}
catch (Exception ex)
{
string ep = ex.ToString();
GeckoHtmlElement ele = (GeckoHtmlElement)node;
}
}
}
//ELEMENT COLLECTION
GeckoElementCollection element = mainbrowser.Document.GetElementsByTagName("div");
foreach (GeckoHtmlElement curelement in element) {
if (curelement.GetAttribute("id") == "minin") {
curelement.InnerHtml = ("hello");
}
}
//DOM
Gecko.DOM.GeckoLinkElement element6 = new Gecko.DOM.GeckoLinkElement(mainbrowser.Document.GetElementById("minin").DomObject);
element6.InnerHtml = "Hello";
//XPATH-ATTEMPT
//var r = mainbrowser.Document.EvaluateXPath("//*[#id='minin']");
//Assert.AreEqual(1, r.GetNodes().Count());
//GeckoElementCollection nodes = mainbrowser.Document.EvaluateXPath(x.ToString()).GetNodes();
//foreach (GeckoNode node in nodes)
//{
// GeckoElement element4 = node as GeckoElement;
//}
Of course it can be done, and it is also very easy:
foreach(var n in mainbrowser.Document.Body.GetElementsByTagName("div"))
{
GeckoHtmlElement hnode = n as GeckoHtmlElement;
if(hnode.Id == "minin")
{
//suppose this DOM: <div id="minin"><span> something </span></div>
hnode.InnerHtml = "<div><h2>hi!</h2></div>";
//outerHtml = "<div id="minin"><div><h2>hi!</h2></div></div>"
hnode.TextContent = "hi";
// outerHtml = "<div id="minin">hi</div>"
hnode.SetAttribute("style", "color: red;");
//outerHtml = "<div style="color: red;" id="minin">hi</div>";
}
}
Maybe you like it with javascript
using (AutoJSContext java = new AutoJSContext(geckoWebBrowser1.Window))
{
string value = "hello there";
string outp = "";
java.EvaluateScript("document.getElementById('minin').innerText ='" + value +"'", out outp);
}
Note: the geckoHtmlElement class has the Id property that has the value of the id attribute of the html tag
<tagName id = "myid">
I don't think it's possible so using selenium web driver instead.

datagridview dont let me change the values of the celll

I'm new in c# , but i can do the basics. i need to change all the values of a column and then update the datagrid. The values are in 20170202 format and i want them like 2017-02-02. the method i did works fine but when i try to set the value to the column it wont change.
here is the code:
private void fixAlldates(DataGridView dataGridView2)
{
string aux1 = "";
for (int x = 0; x < dataGridView2.Rows.Count; x++)
{
if (dataGridView2.Rows[x].Cells[4].Value.ToString() != null)
{
aux1 = dataGridView2.Rows[x].Cells[4].Value.ToString();
dataGridView2.Rows[x].Cells[4].Value = fixDate(aux1);
}
if (dataGridView2.Rows[x].Cells[5].Value.ToString() != null)
{
dataGridView2.Rows[x].Cells[5].Value = fixDate(dataGridView2.Rows[x].Cells[5].Value.ToString());
}
dataGridView2.Refresh();
MessageBox.Show(fixDate(aux1); ----> shows result like i want ex: 2017-02-02
MessageBox.Show(dataGridView2.Rows[x].Cells[4].Value.ToString()); ----> shows 2070202
}
}
private string fixDate(string p)
{
if (p == null) return "No especificado";
String fecha = "" + p.Substring(0, 4) + "-" + p.Substring(4, 2) + "-" + p.Substring(6, 2) + "";
return fecha;
}
sorry for my bad english , im a little bit rusty
Edit:
I fill the data with bindingSource.
private void LlenarProductos(string rut)
{
this.rut = rut;
POLbindingSource1.DataSource = null;
dataGridView2.DataSource = null;
DataClasses1DataContext dc = new DataClasses1DataContext();
dc.CommandTimeout = 0;
System.Data.Linq.Table<ASE_PRODUCTOASEGURADO> producto = dc.GetTable<ASE_PRODUCTOASEGURADO>();
var todoprod = from p in producto
where p.RUT == int.Parse(rut)
select new
{
p.POLIZA,
p.SOCIO,
p.SUCURSAL,
p.COD_PROPUESTA,
p.FECHA_ALTA_COTI,
p.FECHA_ALTA_VCTO,
p.NOMBRE_PRODUCTO
};
POLbindingSource1.DataSource = todoprod; // binding source
dataGridView2.DataSource = POLbindingSource1; // filll
this.dataGridView2.Columns["POLIZA"].HeaderText = "Poliza";
this.dataGridView2.Columns["Socio"].HeaderText = "Socio";
this.dataGridView2.Columns["Sucursal"].HeaderText = "Sucursal";
this.dataGridView2.Columns["COD_PROPUESTA"].HeaderText = "Propuesta";
this.dataGridView2.Columns["FECHA_ALTA_COTI"].HeaderText = "Fecha Cotizacion";
this.dataGridView2.Columns["FECHA_ALTA_VCTO"].HeaderText = "Fecha Vencimiento";
this.dataGridView2.Columns["NOMBRE_PRODUCTO"].HeaderText = "Producto";
// fixAlldates(dataGridView2);
}
From msdn https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.value(v=vs.110).aspx.
The Value property is the actual data object contained by the cell.
So basically the line MessageBox.Show(dataGridView2.Rows[x].Cells[4].Value.ToString()); is getting the value of the underlying data, whereas MessageBox.Show(fixDate(aux1); is actually formatting the date as you require.
You're overlooking the fact that although you're seeing the data in the grid in a specific way, you're not actually changing the data itself.
UPDATE
To actually edit the data in a cell see here

Display records by row number using SqlDataReader

The following code will show the last record in the textboxes. I want to be able to choose which row data to display
while (reader.Read())
{
ListViewItem item = new ListViewItem(reader["item_ID"].ToString());
Item.SubItems.Add(reader["item_Desc"].ToString());
listView1.Items.Add(item);
if(action == "add")
{
txtitemid.Text = "";
txtitem.Text = "";
}
else
{
//this is the part i am taking about
txtitemid.Text = reader.GetValue(0).ToString();
txtitemdesc.Text = reader.GetValue(1).ToString();
}
}
Suppose the last record in the table has an item_ID of 15 and item_Desc is dress then the textboxes will show the following according to code above
txtitemid.Text = 15;
txtitemdesc.Text = "dress";
I want to be able to determine which Item_ID details get displayed in the textboxes
Assign the text box values after your while loop:
if (listView1.Items.Count > 0)
{
var displayedItem = listView1.Items[listView1.Items.Count - 1];
txtitemid.Text = displayedItem.SubItems[0].Text;
txtitemdesc.Text = displayedItem.SubItems[1].Text;
}
else
{
txtitemid.Text = "";
txtitemdesc.Text = "";
}
EDIT:
Similarly, you could display the first item by changing the line in the code above to:
var displayedItem = listView1.Items[0];
if (reader.Read())
{
var readMore = true;
while (readMore)
{
var val = reader.GetValue(0).ToString();
readMore = reader.Read();
if (!readMore)
{
//Last record. Use val .
txtitemid.Text = val;
}
else
{
//Not last record. Process val differently.
}
}
}

Can I group DateTime type data in PivotGrid of DevExpress during runtime?

I have a PivotGrid (DevExpress) within WPF and bind the DataSource to an IList that contains objects of which there are several properties of type DateTime. I want the end-user to choose during runtime which of those DateTime fields the user wants to group by Year, Month, or Day. Is that possible?
I understand that I can provide DateTime groupings programmatically but as there are several DateTime fields it would be quite tedious and unnecessary if the end-user can choose which DateTime field to group and how to group it during runtime.
Can you please guide me how to do that?
I have the following:
<dxdo:LayoutControlItem ItemWidth="1*">
<dxpg:PivotGridControl MaxHeight="800" MaxWidth="800" DataSource="{Binding AllChildOrders}" DataSourceChanged="PivotGridControl_OnDataSourceChanged">
</dxpg:PivotGridControl>
</dxdo:LayoutControlItem>
and in code behind:
private void PivotGridControl_OnDataSourceChanged(object sender, RoutedEventArgs e)
{
var pivotTable = sender as PivotGridControl;
pivotTable.RetrieveFields();
}
The above code works and the pivot table displays all available fields during runtime, including the fields of type DateTime. I do not want to programmatically specify which fields to group in particular ways but let the end-user during runtime choose how and which field to group. Possible?
Alternatively I could imagine to programmatically create sub-groupings as follows: How can I accomplish the following?
0. Pre-generate groups
If you don't want to programmatically specify which fields to group, then you can pregenerate groups for each DateTime field, so user can choose between fields itself and groups of fields.
Here is example:
private void PivotGridControl_DataSourceChanged(object sender, RoutedEventArgs e)
{
var pivotTable = sender as PivotGridControl;
pivotTable.Groups.Clear();
pivotTable.RetrieveFields();
var dateTimeFields = pivotTable.Fields.Where(item => item.DataType == typeof(DateTime)).ToList();
foreach (var field in dateTimeFields)
{
var group = new PivotGridGroup();
group.Add(new PivotGridField() { FieldName = field.FieldName, Caption = field.Caption + " (year)", GroupInterval = FieldGroupInterval.DateYear });
group.Add(new PivotGridField() { FieldName = field.FieldName, Caption = field.Caption + " (month)", GroupInterval = FieldGroupInterval.DateMonth });
group.Add(new PivotGridField() { FieldName = field.FieldName, Caption = field.Caption + " (day)", GroupInterval = FieldGroupInterval.DateDay });
foreach (var groupField in group)
pivotTable.Fields.Add(groupField);
pivotTable.Groups.Add(group);
}
}
Here is screenshot of example:
1. Create sub-groupins
You can create sub-groupings by using PivotGridField.DisplayFolder property.
Here is example:
private void PivotGridControl_DataSourceChanged(object sender, RoutedEventArgs e)
{
var pivotTable = sender as PivotGridControl;
pivotTable.RetrieveFields();
var dateTimeFields = pivotTable.Fields.Where(item => item.DataType == typeof(DateTime)).ToList();
foreach (var field in dateTimeFields)
{
var fieldYear = new PivotGridField()
{
FieldName = field.FieldName,
Caption = field.Caption + " (year)",
GroupInterval = FieldGroupInterval.DateYear,
Visible = false,
DisplayFolder = field.Caption
};
var fieldMonth = new PivotGridField()
{
FieldName = field.FieldName,
Caption = field.Caption + " (month)",
GroupInterval = FieldGroupInterval.DateMonth,
Visible = false,
DisplayFolder = field.Caption
};
var fieldDay = new PivotGridField()
{
FieldName = field.FieldName,
Caption = field.Caption + " (day)",
GroupInterval = FieldGroupInterval.DateDay,
Visible = false,
DisplayFolder = field.Caption
};
pivotTable.Fields.Add(fieldYear);
pivotTable.Fields.Add(fieldMonth);
pivotTable.Fields.Add(fieldDay);
}
}
Here is result:
2. Customize popup menu
You can add commands to field popup menu which allows user to change group interval. For this you can use PivotGridControl.PopupMenuShowing event and PopupMenuShowingEventArgs.Customizations property to customize menu.
Here is example:
private void PivotGridControl_DataSourceChanged(object sender, RoutedEventArgs e)
{
var pivotTable = sender as PivotGridControl;
pivotTable.Groups.Clear();
pivotTable.RetrieveFields();
}
private void PivotGridControl_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
{
if (e.MenuType != PivotGridMenuType.Header)
return;
var fieldHeader = e.TargetElement as FieldHeader;
if (fieldHeader == null)
return;
var field = fieldHeader.Content as PivotGridField;
if (field == null || (field.Group != null && field.Group.IndexOf(field) > 0))
return;
var groupInterval = field.GroupInterval;
if (groupInterval == FieldGroupInterval.Default && field.DataType != typeof(DateTime))
return;
var dateTimeIntervals = new List<FieldGroupInterval>(new FieldGroupInterval[]
{
FieldGroupInterval.DateYear,
FieldGroupInterval.DateQuarter,
FieldGroupInterval.DateMonth,
FieldGroupInterval.DateDay,
FieldGroupInterval.Hour,
FieldGroupInterval.Minute,
FieldGroupInterval.Second,
FieldGroupInterval.DateWeekOfYear,
FieldGroupInterval.DateWeekOfMonth,
FieldGroupInterval.DateDayOfYear,
FieldGroupInterval.DateDayOfWeek,
FieldGroupInterval.Date,
FieldGroupInterval.Default
});
if (!dateTimeIntervals.Contains(groupInterval))
return;
var pivotTable = sender as PivotGridControl;
var subMenu = new BarSubItem() { };
subMenu.Content = "Set group interval";
if (field.Group == null)
{
var button = new BarButtonItem() { Content = "Year - Month - Date" };
button.ItemClick += (s, eventArgs) =>
{
pivotTable.BeginUpdate();
var group = field.Tag as PivotGridGroup;
if (group == null)
{
if (groupInterval != FieldGroupInterval.Default)
field.Caption = field.Caption.Replace(" (" + groupInterval + ")", string.Empty);
group = new PivotGridGroup();
group.Add(new PivotGridField() { FieldName = field.FieldName, Caption = field.Caption + " (year)", GroupInterval = FieldGroupInterval.DateYear, Tag = field, Area = field.Area, AreaIndex = field.AreaIndex });
group.Add(new PivotGridField() { FieldName = field.FieldName, Caption = field.Caption + " (month)", GroupInterval = FieldGroupInterval.DateMonth });
group.Add(new PivotGridField() { FieldName = field.FieldName, Caption = field.Caption + " (day)", GroupInterval = FieldGroupInterval.DateDay });
foreach (var groupField in group)
pivotTable.Fields.Add(groupField);
pivotTable.Groups.Add(group);
group.Tag = field;
}
else
{
var yearField = group[0];
yearField.Area = field.Area;
yearField.AreaIndex = field.AreaIndex;
yearField.ShowInCustomizationForm = true;
}
field.Visible = false;
field.ShowInCustomizationForm = false;
pivotTable.EndUpdate();
};
subMenu.Items.Add(button);
}
foreach (var dateTimeInterval in dateTimeIntervals.Where(item => item != groupInterval))
{
var button = new BarButtonItem() { Content = dateTimeInterval, Tag = field };
subMenu.Items.Add(button);
button.ItemClick += (s, eventArgs) =>
{
pivotTable.BeginUpdate();
var group = field.Group;
if (group != null)
{
var yearField = field;
field = yearField.Tag as PivotGridField;
field.Area = yearField.Area;
field.AreaIndex = yearField.AreaIndex;
field.ShowInCustomizationForm = true;
yearField.Visible = false;
yearField.ShowInCustomizationForm = false;
}
else if (groupInterval != FieldGroupInterval.Default)
field.Caption = field.Caption.Replace(" (" + groupInterval + ")", string.Empty);
field.GroupInterval = dateTimeInterval;
if (dateTimeInterval != FieldGroupInterval.Default)
field.Caption += " (" + dateTimeInterval + ")";
pivotTable.EndUpdate();
};
}
e.Customizations.Add(subMenu);
}
Here is result:

id of $.find control is undefined

I'm trying to generate a control dynamicaly and after change another control. For example i have a button and a label, i want to change label's text using AJAX/JS/etc, without post/get queries. So i'm writing a code like this:
foreach (var pair in FailedMonitorings)
{
var server = (ServerEnum)pair.Key;
var tabPanel = new TabPanel { HeaderText = server.GetDescription() };
var updatePanel = new UpdatePanel();
var upChilds = updatePanel.ContentTemplateContainer.Controls;
var label = new Label { Text = "Hello from UP-" + tabPanel.HeaderText, ID = "lbl" + tabPanel.HeaderText};
upChilds.Add(label);
const string command = #"var ctrl = $.find(""{0}""); alert(ctrl.id); return false;";
var button = new Button {Text = "Button"};
upChilds.Add(button);
tabPanel.Controls.Add(updatePanel);
tbcErrors.Tabs.Add(tabPanel);
button.OnClientClick = string.Format(command, label.ClientID);
}
so generated html here:
for a start i just want to create a messagebox with id of control, but even this simple code doesn't work. Question is: why? And how to solve it?
Added: ctrl is not null
when command is
const string command = #"var ctrl = $.find(""{0}""); alert(((ctrl != null).toString() + ' ') + ctrl.id); return false;";
result is true undefined
I think it should be
const string command = #"var ctrl = $('#{0}')[0]; ctrl.innerText = 'Updated!'; return false;";
Why I say this is in jquery to select an element with an id you would use the same convention as a css selector which means you need to prefix the id with a '#' so $('#elementid') will select for a DOM element like <label id="elementid" /> what I would do is
foreach (var pair in FailedMonitorings)
{
var server = (ServerEnum)pair.Key;
var tabPanel = new TabPanel { HeaderText = server.GetDescription() };
var updatePanel = new UpdatePanel();
var upChilds = updatePanel.ContentTemplateContainer.Controls;
var label = new Label { Text = "Hello from UP-" + tabPanel.HeaderText, ID = "lbl" + tabPanel.HeaderText};
upChilds.Add(label);
const string command = #"updateText('{0}')";
var button = new Button {Text = "Button"};
upChilds.Add(button);
tabPanel.Controls.Add(updatePanel);
tbcErrors.Tabs.Add(tabPanel);
button.OnClientClick = string.Format(command, label.ClientID);
}
then in html
<script type="text/javascript">
function updateText(id){
var ctrl = $('#' + id);
ctrl.text('Updated text');
return false;
}
</script>
I prefer that the button call an updateText function as a posed to rendering all the code inline to the client. It makes the code easier to maintain without having to recompile server side. If you need to work with a dom element then you could use var ctrl = $('#' + id)[0]; this would return the first dom element found for the jquery selection once you have it then you can set the innerText to a value ctrl.innerText = 'Updated!';. I didn't do that in my answer because I just wanted to show how it could be done purely from jquery.
The code
const string command = #"var ctrl = $.find(""{0}""); alert(((ctrl != null).toString() + ' ') + ctrl.id); return false;";
will not work firstly because your jquery selector var ctrl = $.find(""{0}""); will not select the correct control on the client. It would probably render script something like
<button onclick="var ctrl = $.find("Ctrl$Label1");alert(((ctrl != null).toString() + ' ') + ctrl.id); return false;" />
which means that ctrl would not be null but an empty array as there is no dom element like Ctrl$Label1 and since arrays don't have a property of id, it would be undefined. what you are after is a '#' in front of the clientId. The second reason this still will return undefined is that even if you do have a valid selector. Is that the JQuery object returned doesn't have a property of id so you will still see undefined. So finally to get both the id and get the correct selector it would look like
const string command = #"var ctrl = $('#{0}')[0]; alert(ctrl.id); return false;
or if you need to set the text it would look like
const string command =# "var ctrl = $('#{0}')[0]; ctrl.innerText = 'Updated!; return false;

Categories

Resources