I created a data set from an xml file and attached it to a gridview. I would like to do how do i format the data in the dataset or from the gridview, for example, change the header text for a column or also show only certain items in my gridview.
Dim xmlDataSet As New DataSet
xmlDataSet.ReadXml(GlobalClass.GlobalUrl)
GridView1.DataSource = xmlDataSet
GridView1.DataBind()
Is there anyway how to go about manipulating the data inside a dataset? Thank you.
You can try with theses posts :
First definition : http://msdn.microsoft.com/en-us/library/zb0sdh0b.aspx
Note : it's very interessant to read theses links about methods and properties
link 1 : http://msdn.microsoft.com/fr-fr/library/system.data.dataset.aspx
link 2 : http://msdn.microsoft.com/fr-fr/library/system.data.dataset.tables.aspx
You can do this for renaming columns:
xmlDataSet.Tables[0].Columns["CurrentColumnName"].ColumnName = "NewColumnName";
Here is a way to hide or show columns:
xmlDataSet.Tables[0].Columns["ColumnName"].Visible = true;
Related
I am trying to get the content of the email from site name "yopmail.com" which is having multiple frames. I need to switch to the frame name = 'ifmail' and want to getText from email body.
Please see screenshot for yopmail:
Anyone can help me out here?
i use the below code to get the text of email body:
Thread.sleep(4000);
driver.switchTo().frame("ifmail");
List<WebElement> elems = driver.findElements(By.cssSelector("div#mailmillieu>div>div[dir='ltr']>div"));
for(WebElement element: elems){
if(!element.getText().equals("")){
System.out.println("body is "+element.getText());
}
}
i use "" as there are some br and new line in my body. But it will show all the text of ur body.
You can give the name as parameter to the switch command
driver.switchTo().frame("ifmail");
Hi please handle iframe like below
driver.switchTo().frame(int arg0); // Select a frame by its (zero-based) index. That is, if a page has multiple frames (more than 1), the first frame would be at index "0", the second at index "1" and so on.
List<WebElement> iframeElements = driver.findElements(By.tagName("iframe"));
System.out.println("The total number of iframes are " + iframeElements.size());
driver.switchTo().frame(String arg0); // Below is the example code snippet using frame
a.Name.
b.Id.
c.WebElement
driver.switchTo().frame(frame);
System.out.println("Navigated to frame with name " + frame);
Switching back to Main page from Frame
driver.switchTo().defaultContent();
Hope this helps you
You can switch to frame by name, id, webelement , index
Here the HTML of frame:-
<iframe class="whc" frameborder="0" scrolling="auto" id="ifmail" name="ifmail" src=""></iframe>
You id and name have the same name so you can switch it as below :-
driver.switchTo().frame("ifmail");
OR
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[#id='ifmail']")));
Hope it will help you :)
Please try as below, hope it helps:
//Switch to Main page first
driver.switchTo().defaultContent();
//Switch to the desired frame
driver.switchTo().frame(frame);
// perform steps you want to do
//and then Switching to Main page again
driver.switchTo().defaultContent();
LATEST UPDATE: Issue answered here. Some one else at stackoverflow had a similar issue and it was resolved. Solution provided for convenience. This is the line of code I was missing:
comboHeaderColumn.useLabelFunctionForFilterCompare = true;
that line is followed by these:
comboHeaderColumn.filterComboBoxBuildFromGrid = true;
comboHeaderColumn.labelFunction = formatState;
where formatState is a local method that formats the data for the combobox.
UPDATE: I've now got the combobox's loading with the correct data, but when I select a value nothing happens. The combo boxes load only data that is in the column, and when you select a value in the combobox, it's supposed to filter the rows on that value. It doesn't.
Thanks for looking. I'm having trouble getting multiple filters to work in Flex in Flash Builder 4 using the ExtendedDataGrid and ComboBox's. Here is an image of part of the grid:
The User Name and City filter properly if you type text into the box's above the column header and the Request Date lets you select date ranges if you click on the Custom bar, but the Request Reason and State ComboBoxes do not list anything. I've created them using comboHeaderColumn.filterComboBoxBuildFromGrid = true; but all it does is put "[object Object]" as the only other selection under All.
I've used this article but it will only allow you to use a single filter for the entire grid.
My finished grid will have about 20 columns and from 20,000 to 450,000 rows of data so the filters are really important and I'll need more than one.
The code is very straight forward and loops through all the returned data and if the column is identified as a filter column it does this:
comboHeaderColumn.filterComboBoxDataProvider = codeValuePairs;
comboHeaderColumn.filterComboBoxLabelField = "Value";
comboHeaderColumn.filterControl = "ComboBox";
comboHeaderColumn.filterOperation = FilterExpression.FILTER_OPERATION_TYPE_EQUALS;
comboHeaderColumn.headerText = ac.Header;
comboHeaderColumn.dataField = ac.Name;
if( ac.Header == "State" || ac.Header == "Request Reason" )
{
comboHeaderColumn.filterComboBoxBuildFromGrid = true;
}
ProfileDataColumns.push(comboHeaderColumn);
This creates 2 entries in the combo box: All and [object Object]
What am I missing??? Anyway, after half a day searching I decided to reach out.
Any suggestions or direction to an article would be very much appreciated.
Thanks.
I have a List with following values
List<Calculations> calcs = new List<Calculations>();
Calculations cal = new Calculations();
cal.TotalTotalC2 = Convert.ToInt32(reader["TotalTotalC2"].ToString());
cal.TotalTotalC3 = Convert.ToInt32(reader["TotalTotalC3"].ToString());
cal.TotalC1C4IOM = Convert.ToInt32(reader["TotalC1C4IOM"].ToString());
cal.TotalC1C4MDR = Convert.ToInt32(reader["TotalC1C4MDR"].ToString());
calcs.Add(cal);
i need to Bind these Numeric values in the following table format.left hand side plain text and right hand side the bound values.
Can some one plz tell me that how can i use GridView to bind in above format.
you have to write code in RowDataBound event , and check for row number in each iteration and based on the row number bind the column text of your custom list to the column, I don't think there is any auto function to bind column names to grid!!! let me know if you find something direct and easy
I had to dynamically generate a DataTable and then bind it to GridView
DataTable dt=new DataTable();
dt.Columns.Add("Title", typeof(string));
dt.Columns.Add("Count", typeof(int));
foreach (Calculations item in calcs )
{
dt.Rows.Add("Total ...", item.TotalTotalC2);
dt.Rows.Add("Total ...", item.TotalTotalC3);
}
I've got a GridView in ASP.NET 2.0 with AutoGenerateColumns set to true. It'll be bound at runtime to a DataSet with one of many possible schemas, and I'd rather not set up grids and columns for each possible schema.
Some of the columns in the grid will sometimes be floating point values. It seems the default number formatting turns 0.345 into 0.345000. Is there a way to change the default number format so it trims to a set number of decimals?
You could use strings in your schema instead of floating point for display purposes, and perform the formatting manually, something like this:
EDIT: Without LINQ, you can do the same thing by modifying rows in the schema:
// load source data
DataSet myData = GetDataSet();
// create column for formatted data.
myData.Tables["MyTable"].Columns.Add("AmountFormatted", typeof(string));
// apply formatting
foreach (DataRow dr in myData.Tables["MyTable"].Rows)
dr["AmountFormatted"] = string.Format("{0:0.###}", dr["Amount"]);
// remove source column and replace with formatted column
myData.Tables["MyTable"].Columns.Remove("Amount");
myData.Tables["MyTable"].Columns["AmountFormatted"].ColumnName = "Amount";
C#, LINQ-Based solution:
var theData = GetDataSchema1();
var dataSource = theData.Tables["MyTable"].Select().Select(dr =>
new { /* select only columns you want displayed, and apply formatting */
MyColumn1 = dr["MyColumn1"],
MyColumn2 = dr["MyColumn2"],
MyColumn3 = String.format("#.###", dr["MyColumn3"]),
MyColumn4 = dr["MyColumn4"],
MyColumn5 = dr["MyColumn5"]
}
);
MyGridView1.DataSource = dataSource;
MyGridView1.DataBind()
I have a quick question about JQuery. I have dynamically generated paragraphs with id's that are incremented. I would like to take information from that page and bring it to my main page. Unfortunately I am unable to read the dynamically generated paragraph IDs to get the values. I am trying this:
var Name = ((data).find("#Name" + id).text());
The ASP.NET code goes like this:
Dim intI As Integer = 0
For Each Item As cItem in alProducts1
Dim pName As New System.Web.UI.HtmlControls.HtmlGenericControl("p")
pName.id = "Name" & intI.toString() pName.InnerText = Item.Name controls.Add(pName) intI += 1
Next
Those name values are the values I want...Name1, name2, name3 and I want to get them individually to put in their own textbox... I'm taking the values from the ASP.NET webpage and putting them into an AJAX page.
Your question is not clear about your exact requirement but you can get the IDs of elements with attr method of jQuery, here is an example:
alert($('selector').attr('id'));
You want to select all the elements with the incrementing ids, right?
// this will select all the elements
// which id starts with 'Name'
(data).find("[id^=Name]")
Thanks for the help everyone. I found the solution today however:
var Name = ($(data).find('#Name' + id.toString()).text());
I forgot the .toString() part and that seems to have made the difference.