I have a view where a user can enter a bank transaction. So they select an Account, a Payee, a Category (Based on allowable categories for the selected Payee) and a Sub Category (based on the Category selection) - and a value. This is done via JQuery, and is working.
However, there is a requirement to select more than one category/subcategory/amount per transaction (Split the transaction).
I'd like to maybe add a 'grid' (So, a table), and a button under the category/sub category/amount section, labelled 'Add', which then adds the selected Cat/SubCat/Amount to a grid, then blanks the existing selections, ready for more to be added - allowing the user to add as many 'amounts' as needed.
But - how?
On the Add button, I guess I would need to add the CategoryId, SubCategoryId and Amount to a List<>? Then based on that list, build the summary grid?
I'd like there to be no flashing of the screen. Would this have to be done via JQuery? Build the table with JQuery, and then have the list of cats/subcats/amounts sent back to the server on Form submittion?
You might want to look into the jQuery tmpl plugin. This plugins allows you to build client side templates. This is the kind of thing you might want to use on your site.
You define one template of a table row, and each time just add a new row based on that template.
I would give each form item in the table row an extra index variable (such as name="CategoryID-1" for the first row). While inserting a new row, you just send the current index to the template, and make sure the template adds the current index to the names of the form elements.
Then on the server side, you can do a simple query to get all the indeces.
ie
int[] indices = Request.Form.AllKeys.Where(k => k.StartsWith("CategoryID-")).Select(k => Convert.ToInt32(k.Substring(11))).ToArray();
foreach (int index in indices)
{
string cat = Request.Form["CategoryID-" + index.ToString()];
string subcat = Request.Form["SubCategoryID-" + index.ToString()];
//etc.
}
Related
I'm trying to create a simple project, an Inventory management system.
We have a set of items for sale in our inventory (defined in the database) and we dispatch items in the quantity that the customer order.
The issue I have is, a user may order just 1 item, or they may order a 100 items, in whatever quantities they prefer (assume the user of this system gets this info through an email).
So I have some trouble creating the "Sales Order" GUI.
I tried using a ListBox / ListView. There I can select all the items they want and generate a sales order, but I can't enter the corresponding quantity.
It is not practical to have like 20 text boxes in the form.
If I understand your question correctly, it seems as if a good approach would be to have a means of selecting the specific product you want to quantify first. Supermarket POS systems do this through PLU (Price Look Up) codes that identify the product name and price. You could alternately have a search box that combs through your database for product names matching the search query.
After that you can have one text box (I would recommend a number spinner) to select the quantity.
Finally have a button that submits that order of that specific product and move on to the next. You could wait to submit all the quantities needed until the order is completed to signify that it is one unique order if that information is important to you.
For one of my projects I need to allow the user to select some products out of a table.
This table will be paged (+2k records in DB).
So the user needs to be able to select items on different pages without losing them.
I was thinking about using 2 tables. One table to select items from and another table(also with paging) where the selected items will be displayed.
But I have no idea how to persist the selected items without using Sessions...
If anybody has a better idea please share it.
Edit:
It is possible(won't happen that much) to select all products (+2k records).
I don't know how mvc will behave if you have 2k hidden fields.
Also lets say i use hidden fields and have the following in my viewmodel
public List<int> SelectedIds {get;set;}
I can then use hidden fields with "SelectedIds[i]" as name(replacing i by an integer).
But the user can also deselect the items again.
And I don't think the binding will work when you skip numbers.
ex: 2 hidden field with these names "SelectedIds[0]" && "SelectedIds[2]"
This is something I'll have to test when i am home...
im making a Coded UI test in Visual Studio 2010 for a web application in C# and i wish to click a button in the 6th column of a table based on the inner text of column 1? is this possible?
So for instance i have a table with Names in column one and other info and then a button in column 6. All auto generated.
Im assuming if i can get the Row number from the cell with say "John Smith" in it i can then press the button for this row in column 6.
Any ideas? i have tried googling and looking at what parameters i can pass in but im coming up stumped.
Something based on the following may help.
Access the HTML table by copying code from that generated by the Coded UI recorder for an assertion or a click on the cells. You should have something like:
HtmlCell theTable = new HtmlCell(this.UItheWindow.UItheTable.UIItemTable);
Cells of the table can be accessed by adding properties such as:
theTable.FilterProperties[HtmlCell.PropertyNames.RowIndex] = "0";
theTable.FilterProperties[HtmlCell.PropertyNames.ColumnIndex] = "6";
UITestControl cell = theTable.Find();
HtmlCell wantedCell = (HtmlCell)cell;
The above might be used as the body of a method returning the value of wantedCell. The name should now be available as:
wantedCell.InnerText;
Accessing the button to be clicked should follow a similar approach.
Another approach uses the GetChildren method to traverse the table. Start by getting theTable as above. Then have something like
UITestControlCollection children = theTable.GetChildren();
Loop through the children checking row properties. When the required row is found, call the GetChildren of that row and get the loop through them to find the required column. Some points: You may need to loop on columns before looping over rows. You may be able to directly index into the UITestControlCollection for the rows and the columns rather than needing to loop and check values. Depending on exactly how the table was written there may be additional levels between the table and the wanted cells, so you may need to examine children, grand children, great grand children, great great ..., and so on.
I have a couple of extension methods that I use to tackle content in tables(Hand coding, rather than using the recorder) -
This extension method for a table gets the first row in the table that contains the requested text in one of its cells or controls
public static HtmlRow GetRow(this HtmlTable table, string cellContent)
{
if((UITestControl)table == (UITestControl)null)
throw new ArgumentNullException("table");
if(cellContent.Length > 80)
cellContent = cellContent.Substring(0, 80); //Our table cells only display the first 80 chars
//Locate the first control in the table that has the inner text that I'm looking for
HtmlControl searchControl = new HtmlControl(table);
searchControl.SearchProperties.Add(PropertyNames.InnerText, cellContent);
//Did we find a control with that inner text?
if(!searchControl.TryFind())
{
//If not, the control might be an HtmlEdit with the text
HtmlEdit firstTableEdit = new HtmlEdit(table);
//Get all of the HtmlEdits in the table
UITestControlCollection matchingEdits = firstTableEdit.FindMatchingControls();
//Iterate through them, see if any have the correct text
foreach (UITestControl edit in matchingEdits)
{
if(cellContent == ((HtmlEdit)edit).Text)
searchControl = (HtmlControl)edit;
}
}
//We have(hopefully) found the control in the table with the text we're searching for
//Now, we spiral up through its parents until we get to an HtmlRow
while (!(searchControl is HtmlRow))
{
searchControl = (HtmlControl)searchControl.GetParent();
}
//The control we're left with should be an HtmlRow, and should be an Ancestor of a control that has the correct text
return (HtmlRow)searchControl;
}
Once you're able to get the correct row, it becomes relatively easy to get the correct control in that row(Or the correct control in a given cell in that row)
In your example, you've got a button in the 6th column of the row. The button probably has some properties associated with it, but even without them if we can correctly limit our search it will still work. Assume our table is named UITableCustomers - Declare a new button and limit it to only the 6th(Index 5) cell in the row containing "John Smith"
Mouse.Click(new HtmlInputButton(UITableCustomers.GetRow("John Smith").Cells[5]));
Obviously, this call is going to fail if the given text doesn't exist in a control in the table.
Your question is not very clear to me but check out the documentation on jQuery.trigger
This method will let you emulate a clickevent. I hope this is what you need.
I am web developer , working on a part of my project developed in WinForms. So my question could be a basic one. Try to bear with it.
I have two list views on my page and a remove button that works for both.
Problems.
I am not able to select a row in both the list view when I run my program, may be some property needed for it?
If I am able to select the row I want to detect which list view item has been selected, so how would I do that?
I have three columns and have bound the data by using the code below.
listView1.Columns.Add("ID",20);
listView1.Columns.Add("Name",40);
listView1.Columns.Add("Mobile",40);
foreach (var item in dataList)
{
newItem = new ListViewItem();
newItem.SubItems.Add(item.ID.ToString());
newItem.SubItems.Add(item.Name);
newItem.SubItems.Add(item.Mobile.ToString());
listView1.Items.Add(newItem);
}
but the ID column is left blank and the data starts to bind in these sense.
ID Name Mobile
1 abc
2 xyz
So how do I properly show the data?
Lastly I want to use my ID column to delete the data. So if I give width=0, is this the best way to hide a column?
See ListView.FullRowSelect property.
See ListView.SelectedItems property. Note, that by default ListView allows multiselection.
Set item text via constructor: newItem = new ListViewItem(item.ID.ToString());, then add rest of subitems (except of item.ID).
If you want to delete the column, just remove it from the columns collection.
Set
listView1.Items[index].Selected=true;
What I can do:
I aim to create a view where a User Control consisting of a TextBox and a Table is added to a page as needed. The user will type a SQL query in the textbox and the Table will be used to render the results.
What I need to do:
I need to add multiple of these controls to the page as the user requests them. They'll be numbered in steps.
For example:
Step 1 = sql query to get a list of parameters;
Step 2 = sql query which uses the first parameter to return a certain value;
Step 3 = sql query that returns a cumulative sum of values which will be compared to the value in step 2.
Each time the "Add" button is clicked a new user control appears beneath the previous in which I can create my SQL query and produce my answer.
I can do the comparisons and query the database. No issues, I'm just not sure how to re-use controls in MVC.
Any suggestions would be helpful,
Thanks,
George
What you're trying to do is interesting and complicated. I trust you have the logic of the solution well in hand, so I will focus on the simple question you posed: "[How can I] add multiple instances of a user control to a single view page?"
There are, of course, a few ways you could do this. You can use javascript to clone a
block of template html code, which is I would probably do so that I don't have a postback. However, you didn't mention javascript, so you should simply wrap your call to RenderPartial in a foreach loop and feed the loop with an incremental value or a list.
View.aspx:
<%
//loop over sqlQueries in list, rendering a
// partial for each and passing the query into the partial.
foreach(var item in Model.listOfSqlQueries)
Html.RenderPartial("sqlBox", item);
%>
Then, have a button in the view that posts to an ViewResult and returns the same list plus one item.
Controller.cs:
public ViewResult AddQueryBox(ViewModel viewModel)
{
//Add blank sql query to list
viewModel.listOfSqlQueries.Add(new SqlQuery());
//return calling view with newly updated viewmodel
return View("View", viewModel);
}