Splitting Titles in DropDown - asp.net-2.0

My application Drop-down consist of lengthy titles, which exceeds the drop-down beyond the page.
Example Title:
Enter your Name Up to 250 Char Enter your Name Up to 250 Char Enter your Name Up to 250 Char Enter your Name Up to 250 Char.
i can split half of the title with sub string().
Is it possible to bring the next half of the title to next line in Drop-down using C#.

I'm not aware of any property of the DropDownList control that allows you to wrap text, but when I've had items in a DropDownList that exceed the width of the control, I add a tooltip that displays the full text of the item when the mouse hovers over it.
You can do this in code-behind after you've populated the DropDownList:
C#
foreach (ListItem item in DropDownList1.Items)
item.Attributes.Add("Title", item.Text);
VB
For Each item As ListItem In DropDownList1.Items
item.Attributes.Add("Title", item.Text)
End For

Related

How to change a dropdown to a text box for barcode scanning into a field

I have an Appmaker form to create a record that includes a many to one relation to another table. By default, the form creates a dropdown to select the related record from a list. This works fine, but I need to barcode scan (or type) the item name rather than select it.
When I change the dropdown to a text box and bind it to the related table, it greys out and becomes unusable when I preview it. (I get a circle with a line through it when hovering over.)
When I keep both the dropdown and the textbox on the same form, I can select a record from the dropdown and it populates the textbox. After that, the textbox becomes editable and works as desired.
How can I remove the dropdown and make the text box editable?
The problem is that when you bind the textbox to a relational field it is looking for a record not just a value.
My thought is you are going to want to create a text box where you enter/scan in the value and leave it unbound. then in probably the onValueChange event write a script to query the item in the related table that you are trying to relate and set that equal to the field you are trying to edit.I don't know that this code will work haven't tested it but should get you going in the right direction:
var ds = app.datasources.Parts;
ds.query.filters.Part._equals = newValue;
ds.load(function() {
if (ds.item === null) {
alert("Part not found!");
widget.root.descendants.FieldPart.value = null;
}
else {
widget.root.descendants.FieldPart.value = ds.item;
}
});

How to get Multiple selected listbox items to another listbox

In my ASP.NET application I have two listboxes, say Listbox1 and Listbox2. Listbox1 having some listitems and which is in Multiple Selection Mode. If I Press the transfer button the selected items in Listbox1 should be moved to Listbox2. I have tried it for Single Selection Move and it works fine.
Now I need help for multiselection.
Code for Single Selection
strItemText = lstAvailableItems.SelectedItem.Text
iItemCode = lstAvailableItems.SelectedValue
lstAvailableItems.Items.Remove(New ListItem(strItemText, iItemCode))
lstSelectedItems.Items.Add(New ListItem(strItemText, iItemCode))
Listbox image
If I press the > button single selected item will be moved from Available Items listbox to selected items list box. How to do this for multiple selection?
A combination of my original, and #Arman's.
Dim lstRemoveItem As New List(Of ListItem)
For Each li As ListItem In lstAvailableItems.Items
If li.Selected Then
lstRemoveItem.Add(New ListItem(li.Text, li.Value))
' can't remove from the collection while looping through it
End If
Next
For Each li As ListItem In lstRemoveItem
lstSelectedItems.Items.Add(li) ' add to "selected" items
lstAvailableItems.Items.Remove(li) ' remove from the original available items
Next
Use List. Iterate all items in the listbox and whatever it finds to be selected, add it to the list.
Dim lstRemoveItem As New List(Of ListItem)
For Each _item As ListItem In lstAvailableItems.Items
If _item.Selected Then
lstRemoveItem.Add(_item)
'here, method to add item to the first list.
End If
Next
For Each _item As ListItem In lstRemoveItem
lstSelectedItems.Items.Add(_item)
Next
Not exactly what you want, but you can configure the variables easily.

Place item at specific position in dropdown list

Can we place/keep dropdownlist item at particular position. Say for example I want to bind dropdownlist to datasource and then add new item which is placed at particular position in dropdownlist. How can this be possible.
You can use Insert method.
dropDownList.Items.Insert(index, new ListItem("Default Panel", "0"));

how to set the value of a dropdown to its default on pageload

Page has Repeater Control displays students records, when click on any record it displays total info.
it has dropdown list displays list of all departments [ not static items ] comes from
db.<asp:DropDownList ID="ddl_name" runat="server" DataSourceID="Employee" DataMember="Technical"
DataTextField="Last_name"
DataValueField="Emp_code"
FirstItemText="Select Item"
FirstItemValue="0"
BoundColumnName="LastName"
BoundDataMember="DeptCode"
Clear="true"
/> Thanks...
by default it should display the first item..and when the user selects a department and save it, the page reloads and again it should show the default value.
You can do it via DropDownList.SelectedIndex property:
ddl.SelectedIndex = 0;
But I would recommend using Post-Redirect-Get instead and after a redirect-get you will have your dropdown set to default.
You may also try storing selected value in a variable or Session[""]

Invoiced Line Items ASP.NET

I have an invoice form . As you know it has Header and Line Items . When user creates invoice there can be any numner of line items.So users can click "Add Item" to add a new item and all of them needs to be saved together when user save the item.
I think I should use Grid view inside update panel with a footer row to add a new row. And save it to a table in session.When they click save invoice I can get the table from session and save those line items.
Let me know for any better approach than this.
I would create custom forms and add button that will add another line of items.
You can use jQuery append to insert div to existing container that contains all the normal fields:
$(document).ready(function() {
//dynamicId for text box's id
var dynamicId = 0
//event handler for Add button
$('#btnAdd').click(function() {
dynamicId += 1
//append <div> elements inside existing container which has
//the all fields
$('#invoiceItemsContainer').append('<div><input type="text" id="txt' + dynamicId + 'runat="server" /></div>');
});
});
When the form submitted, you can extract all the data from the text box. You do need to come up with a way to check how many line of items are on the list, but this is easy enough for you to figure out.

Resources