Design:
Coding:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadRawMeterialGroup();
}
}
//Material Group
private void LoadRawMeterialGroup(){
DataTable dt = new DataTable();
dt = RM.GetRawMeterialGroup();
if (dt.Rows.Count > 0)
{
DrpMaterialGroup.Items.Clear();
DrpMaterialGroup.DataSource = dt;
DrpMaterialGroup.DataValueField = "rmgrp_code";
DrpMaterialGroup.DataTextField = "rmgrp_name";
DrpMaterialGroup.DataBind();
DrpMaterialGroup.Items.Insert(0, new ListItem("", ""));
}
}
//Material Item Code
private void LoadMCode(){
DataTable dt = new DataTable();
dt = RM.GetRawMaterialMaster();
if (dt.Rows.Count > 0)
{
DrpMCode.Items.Clear();
DrpMCode.DataSource = dt;
DrpMCode.DataValueField = "rm_code";
DrpMCode.DataTextField = "rm_itemcode";
DrpMCode.DataBind();
DrpMCode.Items.Insert(0, new ListItem("", ""));
}
}
//Material Name
private void LoadMName(){
DataTable dt = new DataTable();
dt = RM.GetRawMaterialMaster();
if (dt.Rows.Count > 0)
{
DrpMName.Items.Clear();
DrpMName.DataSource = dt;
DrpMName.DataValueField = "rm_code";
DrpMName.DataTextField = "rm_name";
DrpMName.DataBind();
DrpMName.Items.Insert(0, new ListItem("", ""));
}
}
To Set in properties:
AutoPostback = true;
SelectedIndexChanged = DrpMaterialGroup_SelectedIndexChanged;
//Material Group
protected void DrpMaterialGroup_SelectedIndexChanged(object sender, EventArgs e)
{
string dmg = DrpMaterialGroup.SelectedValue.ToString().Trim();
int mg = 0;
if (dmg != "")
{
mg = Convert.ToInt32(dmg);
}
if (mg > 0)
{
DataTable dt = new DataTable();
dt = RM.MGGetRawMaterialMaster(mg);
if (dt.Rows.Count > 0)
{
DrpMCode.Items.Clear();
DrpMCode.DataSource = dt;
DrpMCode.DataValueField = "rm_code";
DrpMCode.DataTextField = "rm_itemcode";
DrpMCode.DataBind();
DrpMCode.Items.Insert(0, new ListItem("", ""));
}
else
{
DrpMCode.Items.Clear();
}
DataTable dt1 = new DataTable();
dt1 = RM.MGGetRawMaterialMaster(mg);
if (dt1.Rows.Count > 0)
{
DrpMName.Items.Clear();
DrpMName.DataSource = dt1;
DrpMName.DataValueField = "rm_code";
DrpMName.DataTextField = "rm_name";
DrpMName.DataBind();
DrpMName.Items.Insert(0, new ListItem("", ""));
}
else
{
DrpMName.Items.Clear();
}
}
else
{
LoadMCode();
LoadMName();
}
}
//Material item Code
protected void DrpMCode_SelectedIndexChanged(object sender, EventArgs e)
{
string dmc = DrpMCode.SelectedValue.ToString().Trim();
int mc = 0;
if (dmc != "")
{
mc = Convert.ToInt32(dmc);
}
if (mc > 0)
{
DataTable dt = new DataTable();
dt = RM.CodeGetRawMaterialMaster(mc);
if (dt.Rows.Count > 0)
{
DrpMaterialGroup.SelectedValue = dt.Rows[0]["rm_rmgrp_Code"].ToString();
DrpMName.SelectedValue = dt.Rows[0]["rm_code"].ToString();
txtUom.Text = dt.Rows[0]["rm_uom_name"].ToString();
}
}
else
{
LoadRawMeterialGroup();
}
}
No comments:
Post a Comment