MVC :: Filling Dropdownlist With Static Data?
Feb 10, 2010i have html.dropdownlist in my form and i need to fill that with static data.
for example a list of months.
how can i fill dropdownlist.
i have html.dropdownlist in my form and i need to fill that with static data.
for example a list of months.
how can i fill dropdownlist.
I've got a DropDownList in my <EditTemplate> and i'd like to fill it by data from database
(I can't use SqlDatasSource).
How to do that?
i was trying something like that
((DropDownList)((DetailsView)sender).FindControl("autor")).DataSource = MethodIveCreate();
((DropDownList)((DetailsView)sender).FindControl("autor")).DataBind();
on DetailsViewChanging method nut i've got error :/
how do i fill a dropdown list from code behind using LINQ to SQL.
View 7 RepliesI have 3 tables:
SUPPLIER
Id (PK)
Name
City (FK)
State (FK)
CITY
Id (PK)
Name
State (FK)
STATE
Shortname (PK)
Name
1) I'd like to fill 1 dropdownlist with the STATE.Name and the other dropdownlist with the CITY.Name based on the STATE chosen, show up the cities, and after the city is chosen, the SUPPLIERS are shown.
2) Is it ok to make a foreign key field for State inside the City table ?
3) Is it better to create new fields STATE and CITY inside SUPPLIER ?
I have some code which fills a dropdownlist:
pn.DataSource = Datatbl.Tables["datalist"];
pn.DataValueField = "partnumber";
pn.DataTextField = "partnumber";
pn.DataBind();
pn.Items.Insert(0, "");
pn.SelectedValue = ligne["pn"].ToString();
and when the value in the Database in null (""), it throws this error: ArgumentOutOfRangeException: 'pn' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value
The 2 dropdownlist controls are-ddlCountry and ddlState. The 2 database tables are-Country and State Country table has fields named- C_ID(pk) and Country State table fields are-S_ID(pk), State, C_ID I'm able to bind the dropdownlist controls to the database. But I want the contents of ddlState to change according to the Country selected from ddlCountryI don't want to use ajax
View 9 RepliesI am trying to Fill my dropdownlist with two column as textfield and 1 column as value field.
dropdownlist2.items.add(new listitem(??? , ??? )
I used Foreach and many many options , I can assing the textfield easy but value I can't
Dim db1
As
New TripsLinqDataContextDim
listhotel = From th
In db1.Triphotels _
Where th.TripCountryID = cid _
Select
CStr(th.TripHotelID) +
" - " + th.City.TripCityName +
" - " + th.TripHotelName
ListBox1.DataSource = listhotel
ListBox1.DataBind()
This will list hotelname and id and city , but I need to set the Triphotelid as value of item in dropdownlist
I have several dropdownlists which are databound to a SQL DB but I am also needing to add 2 items to them. I am using the code below.
With the code in the Calendar1_SelectionChanged sub (Which is when I want it to fire) It loads the data from the sql but not the static content
If I move the code to the Page_Load sub and add "If Page.IsPostBack Then" then it loads the static content but not the SQL.
[Code]....
Which one is faster? For a dropdownlist binding it the first time and using ViewSate or Turning of viewstate, keeping the data in a static datatable and binding the dropdownlist each time on a postback
View 7 RepliesI can't get my gridview to update? Inserting and deleting work fine. Here is my code:
[code]....
How do I bind a DropDownList inside a DeatilsView?
I have something like that... but I'm unable to bind it.
[Code]....
implementing cascading static dropdownlist in asp.net
View 1 RepliesI am using javascript to validate user input on my aspx page. I am easily able to validate textboxes and dropdown list for differenet scenarios.
Now, on one of my dropdown lists (for country), I need to check if it is an allowed country or not for a particular service. I have stored the valid country list in a static property. Is there a way to validate my dropdownlist selected value against that static property?
function validateService(source, args)
{
var country = document.getElementById('<%= ddDestCountry.ClientID %>');
var service = document.getElementById('<%= ddService.ClientID %>');
// Get allowed country list from my static class
var countryList = document.getElementById('<%= StaticProperties.EUCountryList %>');
if (service.value == "P")
{
// I want to do something like this
if (!countrylist.Contains(country.value))
{
args.IsValid = false;
}
else {
args.IsValid = true;
}
}
return;
}
Update(Additional Information): The static property is read-only so it cannot be tampered with from the page.
I am using a FormView in an online quiz page for displaying the questions and RadioButtons (for answers) http://stackoverflow.com/questions/2438219/online-quiz-using-asp-dot-netNow, I need to pick the questions according to a TestID and a particular Set of that Test. The testid and the set_number would be passed using Session variables.I'm having 3 testIDs and 3 Sets per TestID and, thus, am using 9 tables to store the Questions, the Options and the correct answer.I need help on how to set the FormView so that it extracts the questions from a particular table only. Do I need to use a StoredProcedure ? If yes, how?PS: If I use only one table to store all the questions from each Set and for each TestID, I can do that, but I'd prefer using separate tables.UpdateSOLVED myself[CLOSED]
View 1 RepliesLet's say I have a pdf form file available at website which is filled by the users and submitted to the server. On the server side (Asp.Net) I would like to merge the data that I receive in xml format with the empty pdf form that was filled and save it.
As I have found there are several possible ways of doing it:
Using pdf form created by adobe acrobat and filling it with itextsharp. Using pdf form created by adobe acrobat and filling it with FDF Toolkit .net (which seems to be using itextsharp internally) Usd pdfkt to fill the form. Use pdf form file created with adobe livecycle and merge the data by using Form Data Integration Service
I have a set of images which needs to be displayed horizontally on the page. When the set of images reaches the edge of the browser window, they need to continue being displayed horizontally even if it means a horizontal scroll bar is made (In fact it will almost always result in a horizontal scroll bar forming).
I have tried to find some way to get images to push of the side of the page but can find no way (using basic CSS) without defining a width on a container holding the images (eg. 8000px). This is not possible as the width is dynamic (more or less images may be displayed as they are added to the database)
So my solution in theory:
I now record the dimensions of the image in the database when it is uploaded to the server. Using a repeater, if I add together the width of each image as they are loaded then I can use this number to define the width of the container. Seems to make sense right?
The problem comes when I load the images. I am not great at using the Repeater at the best of times and once again it has got me stuck. I have used the Repeater ItemCreated in my code behind but my variable which I declare (dim i as integer = 1) appears to get reset each time.
When I tried in Repeater OnLoad it didn't seem to work either.
The scenario in question can be found here: [URL]
You can see I have responsed the variable in the top left and they are all 1, hence why I believe the variable is being reset.
I am working with SSRS 2005. I was wondering whether there's a way to dynamically fill the data in each Drilldown table group (ie. when its expaned on toggle). So only those records for which a user has expanded will be filled and the collapsed group's data is not retrieved because it does not need to be shown. This way one can restrict large records coming to report thereby improving the execution time and performance of the report.
View 1 RepliesIs it safe to access asp.net session variables through static properties of a static object?Here is what I mean:
public static class SessionHelper
{
public static int Age
{
get
{
[code]...
Is it possible that userA could access userB's session data this way?
I have a DropDownList within the ContentTemplate and wonder if there are any special considerations I should be aware of filling the list with data prior to displaying the TabPanel?
View 13 RepliesIn a webform I have two textbox (txtDNI and txtAPE), 2 buttons (b1 and b2), 1 gridview (myGV) and 2 functions (dt1 and dt2) that return a DataTable txtDNI will be a parameter for dt1 function and txtAPE will be a parameter for dt2 function
DNI [_______] (b1)
APE [_______] (b2)
[NOM |APE |DNI |DIR |OCUP ]
============================
[ | | | | ]
[ | | | | ]
[ | | | | ]
[ | | | | ]
============================
[ 1 2 3 4... ]
When I press b1 myGV will be fill with the dt1 function's datatable and when I press b2 myGV will be fill with the dt2 function's datatable myGV allows paging=true and when I press the next index (2 or other) It appears a PageIndexChanging error. So the pagination isn't automatic and I have to code the PageIndexChanging event When I use a ObjectDataSource and I connect it with myGV the PageIndexChanging error dessapears and the pagination is automatic The problem is the ODS only have a one selectfunction (dt1 or dt2) but not both and the configuration is on design time
The same happen with the PageIndexChanging event where I fill myGV again (with dt1 or dt2) and set the new index (myGV.PageIndex = e.NewPageIndex) and What is the problem?? ... the problem is, for example, when the user erase txtDNI and change index of pagination ... the PageIndexChanging event is fired and call the dt1 function but the txtDNI(parameter) is empty and occurs an error, the function returns an empty datatable and myGV is empty too for avoid this I create viewstates variables for each function, so I have a 2 viewstates and fill them when the user press b1 or b2 When user press the pagination, the PageIndexChanging event catch the viewstate variable and convert it into a datatable and the problem of the automatic pagination is controled The problem is I don't have 1GV in the webForm I have 5GV in some pages... and I try to avoid...
1. all the code in the PageIndexChanging events of each GV in the webform.
2. use the viewstate variables
I don't want to databind a gridview, I want to be able to add rows myself within c# code. I can see there is a GridViewRow object and wondered if I can use this to add/remove rows as required?
View 5 RepliesI have created a crystal report using dataset(.xsd) in asp.net,c#. It is working fine on local machines and my local machine IIS. on my local machine windows7 is installed. When I uploading it on on windows 8 IIS then data is not coming. Dataset is not filling on windows8 IIS.
View 1 RepliesI have a private static field in my Controller class in an MVC web application.
I have a static method in that controller that assigns some value to that static field, I want to apply lock on that static field until some other instance method in the controller uses the value stored in the static field and then releases it.
DETAILS:
I have a controller named BaseController having a static ClientId field as follows and two methods as follows:-
public static string ClientId = "";
static void OnClientConnected(string clientId, ref Dictionary<string, object> list)
{
list.Add("a", "b");
// I want the ClientId to be locked here, so that it can not be accessed by other requests coming to the server and wait for ClientId to be released:-
BaseController.clientId = clientId;
}
public ActionResult Handler()
{
if (something)
{
// use the static ClientId here
}
// Release the ClientId here, so it can now be used by other web requests coming to the server.
return View();
}
I need a GridView with 6 columns, one of which ("ItemID") is a HyperLink who's URL and text is determined from the C# code as I will get that data from an SQL database
INITIALLY, what I wanted to do, which would have been easy as pie, is:
[Code]....
HOWEVER, this does not work because every row in the Item ID column is filled with "System.Web.UI.WebControls.HyperLink". Apparently, this is what the HyperLink's toString() method returns. Apparently, you can't just throw a HyperLink into a DataRow and call it a day. I need to know how to make this ItemID column into such a HyperLink. It doesn't necessarily HAVE to be a HyperLink control, it just has to be able to call my javascript function on the aspx page, "popUp(URL)"
To give you a visualization of what I'm trying to achieve: this is a change log for an inventory system. The ItemID column indicates what item was altered. However, simply just having a number there doesn't say much, so I'm trying to create a link with the text, for example, "42 (motherboard x)". In other words reader["ItemID"] + " (" + reader["Description"] + ")", and that link will run a javascript function I have called popUp(URL) which takes a URL and opens it in a new window of specific size and location, to view that item's details.
I've tried various other methods such as disabling AutoGenerateColumns and manually create a HyperLinkField, but to no avail, because I couldn't get it to run my javascript function that way.
On a single page, I'd like to fill 2 hyperlink controls as well as a datalist control with table data using one call to the database. The page looks like this:
[Code]....
In the code-behind, I've tried several ways to accomplish filling the labels and the datalist with a single call but I can't make it happen without using either reader.read() or if (reader.read()) on the line before I make the call to fill the labels and the datalist. This fills the hyperlink controls correctly but advances the recordset forward by one, which results in the datalist missing it's first record.
I've tried using while (reader.read()), but I get an "invalid attempt to read when no data is present" error. I've also tried using if (reader.hasrows) but I get the same error as above.Here's an example of one of the 2 ways I can get the labels and the datalist filled with data, but again this advances the recordset forward and I end up missing the row of data:
[Code]....