protected void BindBDdlLOT(string Pn, string Lote)
 {
     DSTPSL = (DataSet)ViewState["DSTPSL"];
     if (DSTPSL.Tables["LOT"].Rows.Count > 0)
     {
         DdlLote.DataSource     = DSTPSL.Tables[2];
         DdlLote.DataTextField  = "LOTE";
         DdlLote.DataValueField = "Codigo";
         DdlLote.DataBind();
     }
 }
        protected void BindBusPn(string PN)
        {
            DSTPSL = (DataSet)ViewState["DSTPSL"];
            DataRow[] DR; DataTable DT = new DataTable();
            GrdAlterno.DataSource  = null; GrdAlterno.DataBind();
            GrdStokAlma.DataSource = null; GrdStokAlma.DataBind();
            GrdMvtos.DataSource    = null; GrdMvtos.DataBind();

            DR = DSTPSL.Tables[0].Select("Codigo ='" + PN + "'");
            if (Cnx.ValidaDataRowVacio(DR))
            {
                DT                         = DR.CopyToDataTable();
                TxtTipo.Text               = DT.Rows[0]["DescTipo"].ToString().Trim();
                TxtDescrPn.Text            = DT.Rows[0]["Descripcion"].ToString().Trim();
                ViewState["CodReferencia"] = DT.Rows[0]["CodReferencia"].ToString().Trim();
                LblTitAlterno.Text         = ViewState["IdimaPnALter"].ToString().Trim() + " [" + ViewState["CodReferencia"] + "]";
                switch (DT.Rows[0]["Identf"].ToString().Trim())
                {
                case "SN":
                    DR = DSTPSL.Tables[1].Select("PN ='" + PN + "' OR Codigo = ''");
                    if (Cnx.ValidaDataRowVacio(DR))
                    {
                        DT = DR.CopyToDataTable();
                        DdlSN.DataSource     = DT;
                        DdlSN.DataTextField  = "SN";
                        DdlSN.DataValueField = "Codigo";
                    }
                    else
                    {
                        DdlSN.DataSource = null;
                    }
                    DdlSN.DataBind();
                    DR = DSTPSL.Tables[2].Select("Codigo = ''");
                    if (Cnx.ValidaDataRowVacio(DR))
                    {
                        DT = DR.CopyToDataTable();
                        DdlLote.DataSource     = DT;
                        DdlLote.DataTextField  = "LOTE";
                        DdlLote.DataValueField = "Codigo";
                        DdlLote.DataBind();
                    }
                    break;

                case "LOTE":
                    DR = DSTPSL.Tables[2].Select("PN ='" + PN + "' OR Codigo = ''");
                    if (Cnx.ValidaDataRowVacio(DR))
                    {
                        DT = DR.CopyToDataTable();
                        DdlLote.DataSource     = DT;
                        DdlLote.DataTextField  = "LOTE";
                        DdlLote.DataValueField = "Codigo";
                    }
                    else
                    {
                        DdlLote.DataSource = null;
                    }
                    DdlLote.DataBind();
                    DR = DSTPSL.Tables[1].Select("Codigo = ''");
                    if (Cnx.ValidaDataRowVacio(DR))
                    {
                        DT = DR.CopyToDataTable();
                        DdlSN.DataSource     = DT;
                        DdlSN.DataTextField  = "SN";
                        DdlSN.DataValueField = "Codigo";
                        DdlSN.DataBind();
                    }
                    break;

                default:
                    DR = DSTPSL.Tables[2].Select("Codigo = ''");
                    if (Cnx.ValidaDataRowVacio(DR))
                    {
                        DT = DR.CopyToDataTable();
                        DdlLote.DataSource     = DT;
                        DdlLote.DataTextField  = "LOTE";
                        DdlLote.DataValueField = "Codigo";
                        DdlLote.DataBind();
                    }
                    DR = DSTPSL.Tables[1].Select("Codigo = ''");
                    if (Cnx.ValidaDataRowVacio(DR))
                    {
                        DT = DR.CopyToDataTable();
                        DdlSN.DataSource     = DT;
                        DdlSN.DataTextField  = "SN";
                        DdlSN.DataValueField = "Codigo";
                        DdlSN.DataBind();
                    }
                    break;
                }

                Cnx.SelecBD();
                using (SqlConnection sqlConB = new SqlConnection(Cnx.GetConex()))
                {
                    string VbTxtSql = "EXEC SP_PANTALLA_ConsultaMovimiento 14,@CRf,'','','',0,0,@Idm,@ICC,'01-1-2009','01-01-1900','01-01-1900'";
                    sqlConB.Open();
                    using (SqlCommand SC = new SqlCommand(VbTxtSql, sqlConB))
                    {
                        SC.Parameters.AddWithValue("@CRf", ViewState["CodReferencia"]);
                        SC.Parameters.AddWithValue("@Idm", Session["77IDM"]);
                        SC.Parameters.AddWithValue("@ICC", Session["!dC!@"]);
                        using (SqlDataAdapter SDA = new SqlDataAdapter())
                        {
                            using (DataTable DTA = new DataTable())
                            {
                                SDA.SelectCommand = SC;
                                SDA.Fill(DTA);
                                GrdAlterno.DataSource = DTA; GrdAlterno.DataBind();
                            }
                        }
                    }
                }
            }
        }