dropdown list fill from MYSQL


in fill_gov() you need to select both gov_id and area_name

 command.CommandText = "select gov_id, gov_name from gov";

set value from gov_id

item_1.Value =
(ds_1.Tables[0].Rows[i]["gov_id"].ToString());
item_1.Text = ds_1.Tables[0].Rows[i]["gov_name"].ToString();

and change the fill_area() select sql as below

command.CommandText = "select area_name from area where
area_name !='' and gov_id =" + DropDownList1.SelectedValue ;

you better use parameterized SQL



dropdown list fill from MYSQL

in fill_gov() you need to select both gov_id and area_name

 command.CommandText = "select gov_id, gov_name from gov";

set value from gov_id

item_1.Value =
(ds_1.Tables[0].Rows[i]["gov_id"].ToString());
item_1.Text = ds_1.Tables[0].Rows[i]["gov_name"].ToString();

and change the fill_area() select sql as below

command.CommandText = "select area_name from area where
area_name !='' and gov_id =" + DropDownList1.SelectedValue ;

you better use parameterized SQL


Using Ajax to fill a cascading dropdown list

The problem here was in the call.

$.ajax({
                type: "POST",
                url: "AjaxController/Index",
                async: true,
                data: "{KovID:" + kovID + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",

Both the type and the url were incorrect. I should have been:

$.ajax({
            type: "GET",
            url: '/Ajax/Index',
            async: false,
            data: { KovID: kovID },
            contentType: "application/json; charset=utf-8",
            dataType: "json",

Why my dropdown list don't fill up textboxes?

I assume SqlDataReader.Read method returns boolean value and you can use it like;

while(reader.Read())
{
    txtGn.Text = reader["Groupno"].ToString();
    txtgname.Text=reader["Groupname"].ToString();
    txtsl.Text=reader["Slno"].ToString();
    txtsn.Text = reader["Subname"].ToString();
}

Also I suspect lstAuthor.SelectedItem.Value is a number instead of a string. You might need to use it without using "".

Also using parameterized queries always a good choice.

selectSQL = "SELECT * FROM tblnewgroup WHERE Groupno =
@Groupno";
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand(selectSQL, con);
cmd.Parameters.AddWithValue("@Groupno", lstAuthor.SelectedItem.Value);
....

Fill dropdown list with month and year using php
$current = new DateTime();
$end = new DateTime('2012-04-11');

echo '<select>';
while ($current > $end) {
  echo '<option>' . $current->format('M, Y') .
'</option>';
  $current->modify('-1 month');
}
echo '</select>';

jquery fill dropdown list

You are working with xml, so you should change contentType to 'text/xml' from your ajax call and change xml managament callback to something like this

xmlDoc = $.parseXML( response.d.toString()),
$xml = $( xmlDoc )
$xml.find('Table').each(function() {
                var OptionValue = $(this).find('RoleID').text();
                var OptionText = $(this).find('Name').text();
                var option = new Option(OptionText,OptionValue);
                $(option).html(OptionText);
                mddlrole.append(option);

            });

better way to fill dropdown list in mvc

Since you know why it's occurring

that's because it uses the model passed from controller which doesn't always contain every item from the database. (because of pagination or after search)

then why not fix it right there. Maybe you need a separate validation table for manufacturers (if you don't already have one).

Model:

public class ProductsModel
{
    public IPagedList<Products> CurrentProducts {get; set;}
    public int ManufacturerId {get; set;}
    public int MinPrice{get; set;}
    public int MaxPrice{get; set;}
}

Controller action:

[HttpGet]
public ViewResult CurrentProducts()
{
    ProductsModel model = new ProductsModel();
    model.CurrentProducts = _repository.Product;
    ViewBag.ManufacturerId = from p in _repository.Product select
p.Manufacturer;
    return View(model);
}

[HttpPost]
public ViewResult CurrentProducts(ProductsModel model)
{
    if(ModelState.IsValid)
    {
        model.CurrentProducts =
_repository.Product.Where(t=>t.ManufacturerId ==
model.ManufacturerId);
        ViewBag.ManufacturerId = from p in _repository.Product select
p.Manufacturer;
    }
    return View(model);
}

And in the view, create a dropdown list like this:

@model MyNameSpace.ProductsModel
@Html.DropDownListFor(model=> model.ManufacturerId, string.Empty);


- Technology - Languages
+ Webmasters
+ Development
+ Development Tools
+ Internet
+ Mobile Programming
+ Linux
+ Unix
+ Apple
+ Ubuntu
+ Mobile & Tablets
+ Databases
+ Android
+ Network & Servers
+ Operating Systems
+ Coding
+ Design Software
+ Web Development
+ Game Development
+ Access
+ Excel
+ Web Design
+ Web Hosting
+ Web Site Reviews
+ Domain Name
+ Information Security
+ Software
+ Computers
+ Electronics
+ Hardware
+ Windows
+ PHP
+ ASP/ASP.Net
+ C/C++/C#
+ VB/VB.Net
+ JAVA
+ Javascript
+ Programming
Privacy Policy - Copyrights Notice - Feedback - Report Violation 2018 © BigHow