I am using Watin to test this page but I am unable to get to the subpage of each row in the table.
http://www.domea.dk/sog-bolig/Ledige-boliger/Sider/default.aspx
Any idea how to loop through each row and click the link to the subpage.
I am able to get a hold of the table that holds each row using:
Table table_name = browser.Table(Find.ById("listTable"));
And then loop through each row using:
foreach (TableRow currRow in table_name.TableRows)
{
var s = currRow.TableCell(Find.ByIndex(0));
}
But I don't know how to get the "onclick" event inside of the cell to be "clicked" using watin.
If you want to click on each row link this is the code you need to use:
using (var browser = new IE("http://www.domea.dk/sog-bolig/Ledige-boliger/Sider/default.aspx"))
{
Table table_name = browser.Table(Find.ById("listTable"));
foreach (TableRow currRow in table_name.TableRows)
{
foreach (var c in currRow.TableCells)
{
if (c.Links.Count > 0)
{
c.Links[0].Click();
}
}
}
}
You were going good but needed to get to the link on each row before you can click on it. In sample code I'm using the first link found on the cell c.Links[0].Click(); if this is going to be used as a production code you need to check that the first link is the one you need, for example, checking that the URL of the link is going to xxxx or it contains a specific web page (.Contains) etc.
Related
Trying to find a way to create a DataGridViewCell that supports multiple links, like this:
Multiple Links in a GridView Example
I know this has been asked a thousand times (I've spent a day combing through them), but please hear me out. I would like one cell to contain multiple links separated by commas. I have found a way to do this with a LinkLabel:
var addresses = new List<string>
{
"http://www.example.com/page1",
"http://www.example.com/page2",
"http://www.example.com/page3",
};
var stringBuilder = new StringBuilder();
var links = new List<LinkLabel.Link>();
foreach (var address in addresses)
{
if (stringBuilder.Length > 0) stringBuilder.Append(", ");
// We cannot add the new LinkLabel.Link to the LinkLabel yet because
// there is no text in the label yet, so the label will complain about
// the link location being out of range. So we'll temporarily store
// the links in a collection and add them later.
links.Add(new LinkLabel.Link(stringBuilder.Length, address.Length, address));
stringBuilder.Append(address);
}
// We must set the text before we add the links.
linkLabel1.Text = stringBuilder.ToString();
foreach (var link in links)
{
linkLabel1.Links.Add(link);
}
linkLabel1.AutoSize = true;
linkLabel1.LinkClicked += (s, e) =>
{
MessageBox.Show((string)e.Link.LinkData);
};
LinkList with Multiple Links Output
I cannot find a way to add this LinkList to a DataGridViewCell. Is it possible to somehow insert this LinkLabel into a DataGridViewCell and still have it function correctly? Or can this same functionality somehow be obtained by using a DataGridViewLinkColumn somehow?
I have a TreeView that is displayed inside a panel. The data in the TreeView is based on data returned from the database. The first time, the data is correct. The second time, the TreeView is not refreshed, and the previous data is still showing in the tree. I checked the list that contain the data. The list returned the correct data. I've Google the issue, and could not resolved it with some of the answers that were posted. Here is a sample code of how the TreeView is being created and added to the Panel.
ReportGroups gr = new ReportGroups();
var Name = gr.GetReportName(groupID);
TreeView tr = new TreeView();
tr.BeginUpdate();
tr.Size = new Size(570, 600);
tr.Name = "Home";
tr.Nodes.Add("Reports Name");
tr.CheckBoxes = true;
if (Name.Count() > 0)
{
foreach (var item in Name)
{
if (item != null)
{
tr.Nodes[0].Nodes.Add(item.reportName);
}
}
}
tr.Nodes[0].ExpandAll();
tr.EndUpdate();
this.pDisplayReportName.Width = tr.Width * 2;
this.pDisplayReportName.Height = 300;
this.pDisplayReportName.Controls.Add(tr);
this.pDisplayReportName.Refresh();
What am I doing wrong?
try to add this.pDisplayReportName.Clear(); so data will not double up. :)
The easy option would be to use this.pDisplayReportName.Controls.Clear(); just after tr.EndUpdate();. But, this would cause an issue if you have other controls within the same Panel.
The best option would be to use this.pDisplayReportName.Controls.RemoveByKey("MyTree"); instead of this.pDisplayReportName.Controls.Clear();
And, another option would be to add a TreeView in design time (with name tr) rather than dynamically to the panel. Then, use tr.Nodes.Clear(); before tr.BeginUpdate(); and remove following two lines from your code.
TreeView tr = new TreeView();
.
.
.
this.pDisplayReportName.Controls.Add(tr);
Cheers
I'm using ASP.NET and I'm dynamically filling up my DropDownList.
Here is my code:
DataTable dtList = new DataTable();
dtList.Columns.Add("Name");
dtList.Columns.Add("Type");
foreach (DataDefinitionResponse dr in _dr)
{
if (dr.Type == "Dropdown")
{
string[] strSplit = dr.ListValue.Split('|');
List<string> lst = new List<string>();
foreach (string word in strSplit)
{
DataRow row = dtList.NewRow();
row["Name"] = word;
row["Type"] = dr.Name;
dtList.Rows.Add(row);
}
}
}
ddlFieldList.DataSource = dtList;
ddlFieldList.DataTextField = "Name";
ddlFieldList.DataValueField = "Type";
ddlFieldList.DataBind();
Now I just want to hide a specific item using Javascript when another DropDownList is selected.
I'm not using SelectedIndexChanged here. I must use Javascript.
Please someone help me with this.
Thx
I don't think you will be able to manipulate the DropDownList with JavaScript and "get away with it" because when the page is subsequently posted back to the server ASP .NET will detect that the DropDownList has been "tampered" with and will throw an exception.
There are flags you can set that stop the error but it is unlikely that you will then be able to use the DropDownList in your code-behind.
You would normally achieve what you are trying to do with SelectedIndexChanged (I know you said you didn't want to) and put the control in an UpdatePanel or similar to avoid a full page post-back / refresh.
function Remove()
{
var DropDownList=document.getElementById('<%=DropDownList1.ClientID%>');
alert(DropDownList.value);
for(i=DropDownList.length-1; i>=0; i--)
{
if(DropDownList.options[i].selected)
{
DropDownList.remove(i);
}
}
}
Is there a way that I can access tabs in umbraco using C#? I am trying to loop through each property in a particular tab so that I can show/hide that section of the website depending on whether that tab has content in it or not.
I have tried ContentType.Tab.GetTab(); but that takes an id and I can't find a tab id anywhere.
Thanks.
you can use getVirtualTabs method then loop foreach property inside that tab
Node current = Node.GetCurrent();
DocumentType dt = DocumentType.GetByAlias(current.NodeTypeAlias);
if (dt != null) {
foreach(var tab in dt.getVirtualTabs) { //get all tabs
foreach(var propertyType in tab.PropertyTypes) { //loop through each property inside the Tab
// propertyType.Name
//....write here your code
}
}
}
I have recently switched over from Java/RMI to C# / .net, and am working on my first project using databinding to update records in Oracle. On this first form I'm building, I have a detail view for vehicle records (VIN, year/make/model, license plate number, that sort of thing). The first thing I did in terms of writing to the DB was saving updates:
private void btn_saveDesc_Click(object sender, EventArgs e)
{
bool isSaved = false;
hJA_VEHICLEBindingSource.EndEdit();
DataSet1.HJA_VEHICLEDataTable ch =
(DataSet1.HJA_VEHICLEDataTable)dataSet1.HJA_VEHICLE.GetChanges();
if (ch == null)
{
MessageBox.Show("There are no changes to save.");
}
else
{
Service<TVDDataService.IService1>.Use(svcProxy =>
{
isSaved = svcProxy.SaveVehicles(ch);
});
if (isSaved)
{
// update the vehicle in the local dataset
var modifiedRows = from row in dataSet1.HJA_VEHICLE
where row.RowState == DataRowState.Modified
select row;
foreach (DataRow row in modifiedRows)
{
row.Delete();
}
dataSet1.HJA_VEHICLE.Merge(ch);
dataSet1.HJA_VEHICLE.AcceptChanges();
}
if(isSaved)
{
MessageBox.Show("The record has been saved.");
}
else
{
MessageBox.Show("The record could not be saved.");
}
}
}
That all seemed ok, so I moved on to adding new records. I made a button (I saw online where various people had said it was as good or better to make your own than use a binding navigator) and put this in its handler:
DataRowView drv = (DataRowView)hJA_VEHICLEBindingSource.AddNew();
currVeh_id = nextID(); // generate arbitrary ID for the record
drv["VEH_ID"] = currVeh_id;
drv["GRNTE_ID"] = lastSelectedGranteeID; // just to have an initial value
hJA_VEHICLEBindingSource.Filter = "VEH_ID = " + currVeh_id;
So there (above) I'm putting initial values into some required columns (VEH_ID is the PK). Then I ran the app, entered a value in the textbox for VIN, and went to save (same code as above) and this time GetChanges() returned null.
So I tried this in the "add new" button handler, in place of the first thing:
DataSet1.HJA_VEHICLERow newRow =
(DataSet1.HJA_VEHICLERow)dataSet1.HJA_VEHICLE.NewRow();
currVeh_id = nextID();
newRow.VEH_ID = currVeh_id;
newRow.GRNTE_ID = lastSelectedGranteeID;
dataSet1.HJA_VEHICLE.AddHJA_VEHICLERow(newRow);
hJA_VEHICLEBindingSource.Filter = "VEH_ID = " + currVeh_id;
Now I have something really interesting happening.
- I can successfully enter and save data on any number of new records, until I select an existing record. If I move to an existing record and then add a new record, then when I go to save the new record, the values that were explicitly set in code get written to the DB but data entered into the GUI do not "take" for the new record.
- I can successfully change any number of existing records, until I enter a new record. If I add one or more new records, save, and then try to save changes to an existing record, the call to GetChanges() returns null (so again, apparently it is not "seeing" what's been entered through the GUI).
So in both of these cases, the change from old to new, or new to old, appears to introduce some condition that makes the datatable unaware of what was entered into the GUI. But in changing from old to new it only takes selecting an existing record, whereas with changing from new to old, it only breaks after saving (if I do a new record but then abandon it without saving, I can modify existing records without problems).
I added this into the save handler, just prior to the actual save (in a loop because ch is a datatable, but really the code is set up to where you have to either save or abandon the new record before moving on - thus the loop only executes once):
foreach (DataSet1.HJA_VEHICLERow r in ch)
{
DataRowView drv = (DataRowView)hJA_VEHICLEBindingSource.Current;
MessageBox.Show(drv["VIN_ID"].ToString());
MessageBox.Show(r.VEH_ID + "\n" + r.GRNTE_ID + "\n'"
+ r.VIN_ID + "'");
}
Where VIN_ID is the column to which this particular textbox is bound (I tried this with other fields on the form too, to verify it wasn't just something flaky about that one textbox). The first message box (DataRowView from the binding source) shows the vin that I entered into the textbox. The second message box (row from the table returned by GetChanges()) shows the empty string for VIN_ID, although it has the correct (set through code) values for VEH_ID and GRNTE_ID. The same thing happens if I select a different value for GRNTE_ID using the combo box bound to that column; the row from the datatable still has the value that was set through code, "unaware" of the value selected through the GUI.
Why would the datatable and binding source have different values for the same field? And why would the datatable be able to "see" values entered through the GUI only until the user switches from existing to new, or from new to existing?
Thanks.
Angel:
I'm doing that in my Service:
public bool SaveVehicles(DataSet1.HJA_VEHICLEDataTable vehicles)
{
bool saved = false;
if (vehicles != null && !vehicles.HasErrors)
{
HJA_VEHICLETableAdapter ta = new HJA_VEHICLETableAdapter();
int result = ta.Update(vehicles);
saved = (result > 0);
}
return saved;
}
This is called from this block from my original post:
Service<TVDDataService.IService1>.Use(svcProxy =>
{
isSaved = svcProxy.SaveVehicles(ch);
});
Johannes:
The call to EndEdit() is the second line in the save handler (near the top of my post). Should I be calling it somewhere else as well?
Thanks.
Just to clarify: SaveVehicles cannot be the source of the problem, since the problem is appearing before SaveVehicles is ever called. What condition could cause a discrepancy between the BindingSource and the DataTable after EndEdit() has been called and before anything actually writes to the DB?
You have to update your table adapter after use EndEdit(); also you can update your complete DataSet with the follow snippet :
this.BindingSource1.EndEdit();
this.TableAdapter1.Update(this.DataSet1);
Hopes Helps...
*IF you are using a BindingSource as well:
Just do a simple BindingSource.EndEdit() and your TextBox data will be sent over to the DataTable.
Example:-
_bsHeader.EndEdit();
if (_dsHeader.HasChanges())
{
DataTable dsInsert = _dsHeader.GetChanges(DataRowState.Added).Copy();
_objDal.Insert(dsInsert);
}
Hope this helps anyone who stumbles here.