Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropdown value cannot view in "Add/Edit record form" box using C#.net #2262

Open
AhmadYusoff opened this issue Aug 20, 2021 · 4 comments
Open

Comments

@AhmadYusoff
Copy link

Hello I am new to jtable and like to improve programming skill but i am stuck on dropdown function and unable to display inside ADD/EDIT form . It come out weird value of dropdown is "undefined" . If i manual hardcore for options of Juice name will not issue and working fine.

Below is my code:

In controller part:

public JsonResult GetJuiceLists()
{
try
{
SelectList listJuice;
var sql = "SELECT JUICE_ID,JUICE_NAME FROM JUICE";
listJuice = new SelectList(SqlDbContext.getDropdownList(sql), "Value", "DisplayText");
return Json(new { Result = "OK", Options = listJuice}, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
return Json(new { Result = "ERROR", Message = ex.Message });
}
}

public List<ViewModels.Dropdown_VM> getDropdownList(string sql)
    {
        try
        {

            var list = new List<ViewModels.Dropdown_VM>();
            ConnOpen();
            SqlCommand SQLcmd = new SqlCommand(sql, _SQLconn);
            SQLcmd.CommandTimeout = 30;
            SQLcmd.CommandText = sql;
            SQLcmd.Connection = _SQLconn;

            SqlDataReader dr = SQLcmd.ExecuteReader();
            while (dr.Read())
            {
                list.Add(new ViewModels.Dropdown_VM
                {
                    Value = dr.GetInt32(0),
                    DisplayText = dr.GetString(1)
                }
                    );
            };
            return list;

        }
        catch (Exception exc)
        {
            throw exc;
        }
        finally
        {
            ConnClose();
        }
    }

In javascript part :

fields:{
....
JUICE_ID: {
list: false,
title: 'Juice',
width: '12%',
options: '/Fruit/GetJuiceLists'
//options: {
// '1': 'APPLE', '2': 'BANANA', '3': 'CHERRIES', '4': 'DRAGON FRUIT', '5': 'MANGO', '6': 'PINEAPPLE',
// '7': 'GUAVA', '8': 'HONEYDEW MELON', '9': 'CHERRIES', '10': 'WATERMELON', '11': 'KIWI', '12': 'OTHERS'
// }
},
.....
}

Can someone has any experience with that issue? Thank you so much.

@misterparsons
Copy link

The jtable definition looks fine, so the problem must be with the json response from the server.

Can you post the server response here for further investigation.

@AhmadYusoff
Copy link
Author

json response from server coding on below:

public JsonResult GetJuiceLists() { try { SelectList listJuice; var sql = "SELECT JUICE_ID,JUICE_NAME FROM JUICE"; listJuice = new SelectList(SqlDbContext.getDropdownList(sql), "Value", "DisplayText"); return Json(new { Result = "OK", Options = listJuice}, JsonRequestBehavior.AllowGet); } catch (Exception ex) { return Json(new { Result = "ERROR", Message = ex.Message }); } }

@misterparsons
Copy link

I meant, what is the json text arriving at the browser?

I'd expect to see something like

{"Result":"OK","Options":[{"Value":"101","DisplayText":" Paperback"},{"Value":"102","DisplayText":" Hardcover"}]}

@dasguptahirak
Copy link

@AhmadYusoff
You can view the ajax response of '/Fruit/GetJuiceLists' in Network tab under "Developer Tools". Share that response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants