PDA

View Full Version : [CLOSED] Set selected value to combox when edit data in MVC version 2.x



matrixwebtech
Jun 10, 2014, 7:59 PM
I am very new with EXT.NET,don't have very much idea.

combo box code

X.ComboBoxFor(obj => obj.MaterialGroupID)
.ID("ddlMaterialGroupID")
.FieldLabel("Group")
.AnchorHorizontal("100%")
.EmptyText("Select a Module")
.DisplayField("MaterialGroupName")
.ValueField("MaterialGroupID")
.Store(
Html.X().Store()
.Data(ViewBag.materialgroup)
.ID("StoreMaterialGroupID")
.Model(
Html.X().Model()
.IDProperty("MaterialGroupID")
.Fields(
Html.X().ModelField().Name("MaterialGroupID").Type(ModelFieldType.Int),
Html.X().ModelField().Name("MaterialGroupName").Type(ModelFieldType.String)

)
)

)

controller code




public ActionResult Index()
{

ViewBag.materialgroup = Pur_Master_MaterialGroup_Get();

return View(Views.view.PurchaseManagement_MasterManagemen t_MaterialCategory_Index);
}

private List<tbl_Pur_Master_MaterialCategory> Pur_Master_MaterialCategory_GetParent()
{
List<tbl_Pur_Master_MaterialCategory> _tbl_Pur_Master_MaterialCategory = new List<tbl_Pur_Master_MaterialCategory>();
tbl_Pur_Master_MaterialCategory obj_tbl_Pur_Master_MaterialCategory = new tbl_Pur_Master_MaterialCategory();
_UserSession = (UserSession)Session[AppSession.SessionCurrentUser];

obj_tbl_Pur_Master_MaterialCategory.BranchID = _UserSession.BranchID;
obj_tbl_Pur_Master_MaterialCategory.CompanyID = _UserSession.CompanyID;
_tbl_Pur_Master_MaterialCategory = _MaterialCategory.Pur_Master_MaterialCategory_GetP arent(obj_tbl_Pur_Master_MaterialCategory);
return _tbl_Pur_Master_MaterialCategory;
}
public DirectResult Edit(string selected)
{
SelectedRowCollection src = JSON.Deserialize<SelectedRowCollection>(selected);
Int64 lRecordID = 0;
foreach (SelectedRow row in src)
{
lRecordID = Convert.ToInt64(row.RecordID);

}
tbl_Pur_Master_MaterialCategory _tbl_Pur_Master_MaterialCategory = new tbl_Pur_Master_MaterialCategory();
_tbl_Pur_Master_MaterialCategory.MaterialCatergory ID = lRecordID;
_tbl_Pur_Master_MaterialCategory = _MaterialCategory.Pur_Master_MaterialCategory_GetB yMaterialCatergoryID(_tbl_Pur_Master_MaterialCateg ory);


X.GetCmp<ComboBox>("ddlMaterialGroupID").Value = _tbl_Pur_Master_MaterialCategory.MaterialGroupID.T oString();

X.GetCmp<Window>("Window1").Show();
return this.Direct();
}



But after click on edit button ,window open,but its not set the selected value.
you can see live example here
http://legalinfoservices.com/home
Purchase Management->Master Management->Material Category

Daniil
Jun 11, 2014, 6:06 AM
Hi @matrixwebtech,

Welcome to Ext.NET!

Please try to replace

X.GetCmp<ComboBox>("ddlMaterialGroupID").Value = _tbl_Pur_Master_MaterialCategory.MaterialGroupID.T oString();
with

X.GetCmp<ComboBox>("ddlMaterialGroupID").SetValue( _tbl_Pur_Master_MaterialCategory.MaterialGroupID);

I guess the values in the ComboBox are type of int, but .Value takes a string only. The SetValue method takes an object and should work correctly in that case.

matrixwebtech
Jun 11, 2014, 10:52 AM
Hi @matrixwebtech,

Welcome to Ext.NET!

Please try to replace

X.GetCmp<ComboBox>("ddlMaterialGroupID").Value = _tbl_Pur_Master_MaterialCategory.MaterialGroupID.T oString();
with

X.GetCmp<ComboBox>("ddlMaterialGroupID").SetValue( _tbl_Pur_Master_MaterialCategory.MaterialGroupID);

I guess the values in the ComboBox are type of int, but .Value takes a string only. The SetValue method takes an object and should work correctly in that case.

Hi Daniil,

Can you please let me know make combobox read only,and how I get Selectedvalue from combobox

Daniil
Jun 11, 2014, 3:03 PM
Please clarify is the initial issue resolved? If so, we can close the thread.

You are welcome to start new threads for new questions. Please keep one issue per thread.