Databound Checkbox list with textboxes in a webform - asp.net

I'm having trouble coming up with a solution for the following problem and i was wondering if someone here would help me out.
I need to pull a list of supplies from a db table and list them along with two textboxes (one for quantity, and another for manufacturer)
so the list would look something like this.
checkbox for supply 1 | Quantity | Manufacturer
checkbox for supply 2 | Quantity | Manufacturer
..
I also need to store all of the checked items in a db table.
I'm not sure how i should go about doing this. I've heard some talk about a repeater control being useful but i've not come across any examples that do this type of thing.
Thanks in advance

I've used the ListView for things like this, but Repeater probably woudl work too; simply create the ItemTemplate with these controls. On a button click, you can loop through the ListView.Items collection, using FindControl to find the checkbox, and if checked, get the textbox values.
It's pretty easy to setup.

Related

How to populate many textboxes from a sql query automatically?

This might be a silly question. But I have a lot of textboxes in an in asp.net form I need to populate with data from a sql query.
If the query column names and textbox names are all the same, is it possible to populate the textboxes from the query data automatically? Maybe using loop? There are too many fields so I think it is stupid to populate each field individually using something like:
textboxX.text = data.getValue(0).ToString();
textboxY.text = data.getValue(1).ToString();
...
I am thinking there must be a simpler way to populate all of the textboxes. Can anyone please help me to do this? A simple example would be great.
If you were using something like MVC or MVVM then it would be in a manner of speaking. You could tie your view page to a model that has properties corresponding to the fields. Then in your view page you would bind the model properties to the fields.
If you don't work with MVC/MVVM/knockout then the best thing you could do is to loop your form's controls and assign them some values from your list. For this purpose it's simplier if your controls are named like Ctrl1, Ctrl2, etc - it's just to simplify the looping/assignment

Filtering nested repeaters & paging correctly

I've got a Repeater displaying a list of Countries, and nested within this is another Repeater displaying categories, and nested within this is another Repeater displaying news articles.
This is working fine, however users should be able to enter a keyword and filter the search.
What is the best way of filtering this? Am I going to have to pass identical parameters to 3 different SQL Commands? I'd rather not..
Also, how can I then page this correctly so there are still x amount of articles per page?
Any help much appreciated.
If you store resultset from your DB in a DataTable, and then bind that table to the repeater you can filter the table by using DataTable.Select() method.

Gridview: column with different controls is different modes

Here is my scenario.
I have an objectdatasource-bound gridview where i want to show Students {name, age, class}
name:string, age:int, Class:Foreign key, int
I also want to edit it, but when doing so i want to show a dropdownlist for the class field.
Currently i solve this by
a)creating a view, binding the grid to that view
b) on the editItemTemplate, put a DDL and bind it to the Class table.
What i want to know is if there is a way without involving the view shortcut.
NOTE: this question, Bind column to a different entity source than the gridview is
is somewhat related, but not quite the same thing. in that example, the OP just wanted to show the related data. Since am also updating, i need both the key and the value.

Easiest method to build where clause from checked items in DataList of PreviousPage

I have a selection list that is generated dynamically, it lists a number of checkboxes that are based on an end-user editable table, as such I have no idea what data, or how much, might be contained in this table and how many checkboxes or what they might contain, other than the primary keys of the table.
The user will select the checks they wish to see, and then control is passed to another page via PostBackUrl. The second page has to figure out which records to show (build it's where clause) based on the checkboxes checked in the previous page.
So, my problem is several-fold. First, asp:CheckBoxes don't have values. This can be worked around by a number of methods. Right now, i'm using a placeholder and dynamically creating the checkboxes in the ItemDataBound event of the DataList. I set the ID to "CheckboxKey1Key2" (where Key1 and Key2 are the primary keys of the check items).
Second, I have to walk through the controls of the PreviousPage to dig out all these values. That in itself is also a pain, but doable.
Now, my thinking is to build the where clause of my Linq2Sql query based on the keys I got from decoding the checked checkbox names. This all seems like a lot of jumping through hoops for something that shouldn't be this difficult. Am I missing something? Does anyone have any better solutions?
Make a class with a structure for your values that will be useful and easy for you to use on the result page. Then when the user clicks whatever it is they click to go to the result page, loop through the DataList, create a collection from the checked items, and you will only need to grab one object instead of everything, when you need to format your query.
Then when you get to the result page, loop through the collection and build the query in the loop. Pretty easy and not much code.

how do I create an array or list of ASP.NET checkboxlists

I know how to use the checkboxlist in ASP.NET to display options retrieved from a database. What I don't know how to do is to make this 2-dimensional. That is, I need a list of checkboxlists where I don't know how long the list is; both dimensions of the checkboxlist will be determined by
list of people (pulled from database)
list of tasks (pulled from database)
and the user of the web page will click in column/row to specify which people will be assigned which tasks.
Right now I'm thinking that my only option is to brute-force it by creating a table and populate each cell with its own checkbox. (yuck)
Is there a more elegant way to create a 2-dimensional array of checkboxes with labels for both rows and columns?
I would use a repeater along with a checkboxlist. Depending on how your database is setup you could have each checkboxlist databound.
I've done this before and resorted to the brute-force method you suggest.
It's not as nasty as you'd think. Other solutions that were declarative and databound would likely be just as convoluted and confusing.
I use the ASPxGridView from DevExpress. It has a control column type of Selected (or something like that) which will display a checkbox in the column with the other column populated from your bound datasource. The User can select any rows desired by checking the checkbox on the row and you can get all the selected rows easily inot a collection to process. DevExpress components really do get rid of a lot of brute-force programming.
You can programmitaclly use a GridView control. It's inherently two-dimensional and you can use databound CheckBoxFields for it.
If you're looking for a quick and dirty way, you can use the AJAX Control Toolkit with the two controls and can populate one based on the other. If that's not what you're looking for, I'd do it the brute force way.

Resources